3 回答
TA贡献1871条经验 获得超13个赞
您必须从定义附加功能的同一范围内调用 startActivity:
public void addEvent(View view){
EditText timeEditText = findViewById(R.id.timeEditText);
EditText descriptionEditText = findViewById(R.id.descriptionEditText);
Intent intent = new Intent(getApplicationContext(), events.class);
String timeInfo = timeEditText.getText().toString();
String descriptionInfo = descriptionEditText.getText().toString();
intent.putExtra("time", timeInfo );
intent.putExtra("description", descriptionInfo);
startActivity(intent);//add this
}
TA贡献1798条经验 获得超7个赞
在您的 addEvent() 方法中,
public void addEvent(View view){
//your code
Intent intent = new Intent(addEvent.this, events.class);
Bundle bundle = new Bundle();
bundle.putString("time", timeInfo);
bundle.putString("description",descriptionInfo);
intent.putExtras(bundle);
startActivity(intent);
}
然后,在您的事件活动和 onCreate() 方法中,
Bundle bundle = getIntent().getExtras();
String time = bundle.getString("time");
String description = bundle.getString("description");
ArrayList<ListItem> arrayList = new ArrayList<>();
ListItem listItem = new ListItem(time, description);
arrayList.add(listItem);
adapter = new MyAdapter(this, arrayList);
recyclerView.setAdapter(adapter);
这将完成您的工作。
添加回答
举报