[英]How to change textview text from another activity on button click in android studio?
I have seen a lot of tutorials that gives answer for this, but I don't get it. 我已经看过很多教程可以为此提供答案,但我不明白。 It isn't working. 它不起作用。 I have a button in MainActivity
, that has click listener that does this: 我在MainActivity
有一个按钮,它具有执行此操作的单击侦听器:
Intent i = new Intent(MainActivity.this, DetailsActivity.class);
i.putExtra("Name", "RESULT");
startActivity(i);
Another actiivty: 另一个活动:
txtview = (TextView) find.....(R.id.textView1);
Intent i = getIntent();
String str = i.getStringExtra("Name");
txtview.setText(str);
I don't use an emulator, I build the apk and then transfer it to my mobile. 我不使用模拟器,我构建apk然后将其传输到我的手机。 So in my mobile when I click the button, it closes and says "The app is not responding" XML: 因此,当我单击按钮时,在我的手机中,它会关闭并显示“应用程序没有响应”XML:
<TextView
android:text="result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="145dp"
android:id="@+id/txt" />
Change your TextView id to textView1. 将TextView标识更改为textView1。
findViewById method is returning null beacause there is no TextView with id textView1 findViewById方法返回null,因为没有带有id textView1的TextView
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.