我有一个需要从第二个活动更新的TextView活动。 我可以将文本视图数据传递给第二个活动,但是当我尝试在第二个活动内更新该TextView 时,它会崩溃。我的代码:无法从其他活动更新TextView
1日活动(其中TextView的是我的XML定义):
Intent intent = new Intent(1stactivity.this, 2ndactivity.class);
intent.putExtra("homescore_value", ((TextView)findViewById(R.id.score_home)).getText());
startActivity(intent);
// code snippet
然后在我的第二个活动:
Bundle bundle = getIntent().getExtras();
hometext = bundle.getString("homescore_value"); // this works and displays the correct String from 1st activity,
但是当我尝试拉进来,因为它崩溃a TextView
:
// other code snipped
int homescore = 0;
String Home_nickname = "HOME ";
TextView homestext = (TextView) bundle.get("homescore_value");
hometext.setText(Home_nickname +": "+homescore );
请大家帮忙。
请粘贴LogCat异常 – Sarmad