如何从另一个类设置的TextView(Android版) [英] how to set TextView from another Class (Android)
问题描述
我有这个code,但它不工作(强制关闭)
,我用这个在C#中,但它不是用Java开发的
i have this code but it doesnt work (Force Close) ,i use this in C# but its not working in java
ClassA的C =新ClassA的();
c.TextView1.setText(测试);
ClassA c = new ClassA(); c.TextView1.setText("test");
我需要设置从ClassB的文本视图能不能做到
不使用意图
因为意图需要从头开始的活动,所有的数据都将丢失。
i need to set the text view from ClassB can it be done without using the Intent because the Intent need to start the Activity all over and all the data will be lost
任何人都可以提出一个code此
can anyone suggest a code for this
也可以设置我从ClassB的在ClassA的整型x值
also can i set the int x value in ClassA from ClassB
推荐答案
是的,你可以做 -
Yes, you can do -
Intent i = new Intent(classA.this, classB.class);
Bundle bundle = new Bundle();
bundle.putExtra("name For Identification", "Value);
i.putExtras(bundle);
startActivity(i);
在你的第二课堂,我的意思的 B类
In your second class, i mean Class B
Bundle bundle = getIntent().getExtras("name for Identification");
String text = bundle.getString("name For Identification");
只需将此文本设置为你的的TextView
而且,在 B类也应该延长活动
否则, getIntent()
code将无法工作。
Simply set this text to your TextView
And, the Class B also should extends the Activity
Otherwise, the getIntent()
code will not work.
这篇关于如何从另一个类设置的TextView(Android版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!