安卓:从另一个活动设置文本视图的文本不工作 [英] Android: Set Text View's text from another activity Not working
本文介绍了安卓:从另一个活动设置文本视图的文本不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个活动和2类。
在我的主类,当我点击提交按钮会开始另一项活动。这里是code。
In my Main class, when i click submit button it will start another activity. here is the code.
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, NewActivity.class));
newActivity.setViewValues(fNameET.getText().toString(), lNameET.getText().toString(), mInitialET.getText().toString(), "Female", "birthday", addressET.getText().toString(), cNumberET.getText().toString());
}
的newActivity是其他活性和setViewValues的一个目的是它的方法。
The newActivity is an object of the other activity and the setViewValues is the method of it.
这是不行的,这是我要做的事在Java GUI中。也许缺少的东西。
This doesn't work, this is how i do it in java gui. Maybe something is missing.
谁能帮我这个?
推荐答案
您应该传递的数据是这样的。
You should pass the data like this.
MainActivity.java
Intent intent = new Intent(MainActivity.this, NewActivity.class));
intent.putExtra("firstName",fvalue);
intent.putExtra("lastname",lname);
......
startActivity(intent);
NewActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layoutname);
Intent intent = getIntent();
String firstName = intent.getStringExtra("firstName");
String lastName = intent.getStringExtra("lastname");
}
这篇关于安卓:从另一个活动设置文本视图的文本不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文