创建 Intent 方法后,我无法从 MainActivity 访问我的 UI。当我从 MainActivity 中选择 SelectPLayer 和 SelectPLayer2 活动时,我的应用程序崩溃。我也无法让 Clickable ListViews 转到 GameEmulator 中的指定 TextView。
//MainActivity.java
//Class to select player 1
public class SelectPlayer extends Activity {
//Public static array list with adapter to crete the array and reference for listview being sent by intent from AddPLayer class
public static ArrayList<String> list = new ArrayList<>();
public static ArrayAdapter<String> adapter;
ListView selectView;
TextView title;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.selectplayer);
//Identify selectview ListView
selectView = findViewById(R.id.selectview) ;
selectView.setClickable(true);
selectView.setVisibility(View.VISIBLE);
//Using adapter for ListView menu
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list);
selectView.setAdapter(adapter);
selectView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String item =(String) parent.getItemAtPosition(position); // finding the item which has been clicked by the user
Intent intent = new Intent(SelectPlayer.this, GameEmulator.class); //starting an intent to call GameEmulator Activity
intent.putExtra(GameEmulator.value, item);// Putting the value clicked by user in intent
startActivity(intent); // starting GameEmulator Activity
}
});
杨魅力
相关分类