创建 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 } });
1 回答
杨魅力
TA贡献1811条经验 获得超6个赞
String data = i.getExtras().getString("text_key");
你getExtras()
正在返回空值。确保正确初始化您的意图。
添加回答
举报
0/150
提交
取消