简体   繁体   English

如何在android studio中点击按钮时从另一个活动更改textview文本?

[英]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.

相关问题 如何通过在 android 工作室中单击按钮从另一个活动中更改活动中的 AsyncTask 变量? - How to change a variable of an AsyncTask in an activity from another activity by a button click in android studio? Android,如何在单击按钮时更改Textview? - Android, How to change Textview on button click? Android:通过单击按钮,将一个活动的TextView添加到另一个活动的ListView中 - Android: Add TextView from one activty, to ListView in another activity through a button click 如何在Android Studio中从活动到片段单击意图 - how to intent with on click button from activity to fragment in android studio Android从另一个类更改TextView文本 - Android Change TextView text from another class android studio - 如何将文本从一个活动获取到另一个活动? - android studio - how to get text from one activity to another? 如何通过在另一个活动中单击按钮来更改TextView的颜色? - How to change the color of a TextView in one activity by clicking a button in another? 如何将文本从一个活动传递到另一个活动(android studio) - How to pass text from one activity to another activty (android studio) 如何在Android Studio(Java)中的另一个活动中将timepicker中的时间值传递给textView? - How to pass time value from timepicker to textView in another activity in Android studio(Java)? 如何从Android Studio上的片段更改TextView - How change a textview from a fragment on android studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM