有個問題想要問一下:
因我想要用arraylist 把值 直接傳到下一頁,在網路上,我有查到:
https://stackoverflow.com/questions/16462163/java-how-to-access-an-arraylist-of-another-class
但為什麼我把它改成這樣:
public class MainActivity extends AppCompatActivity {
private int number1 = 50;
private int number2 = 100;
private List<Integer> list;
ARView arView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = new ArrayList<Integer>();
list.add(number1);
list.add(number2);
arView = new ARView(this);
addContentView(arView, new WindowManager.LayoutParams(WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.FILL_PARENT));
getWindow().clearFlags( WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
public List<Integer> getList() {
return list;
}
public class ARView extends View{
MainActivity number;
public ARView(Context context) {
super(context);
number = new MainActivity();
List<Integer> list = number.getList();
Log.i("Volley33", String.valueOf(list));
}
}
}
我log了list 的value, 它是null呢?
不知道是不是我哪邊的觀念不對,能否請幫忙指正??
我用的語言是android studio 的JAVA
謝謝