[英]Android: Set Text View's text from another activity Not working
I have 2 activities and 2 classes. 我有2个活动和2个班级。
In my Main class, when i click submit button it will start another activity. 在我的Main类中,当我单击提交按钮时,它将启动另一个活动。 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());
}
The newActivity is an object of the other activity and the setViewValues is the method of it. newActivity是另一个活动的对象,setViewValues是它的方法。
This doesn't work, this is how i do it in java gui. 这不起作用,这就是我在java gui中的表现。 Maybe something is missing.
也许缺少一些东西。
Could anyone help me with this? 任何人都可以帮我这个吗?
You should pass the data like this. 你应该传递这样的数据。
MainActivity.java MainActivity.java
Intent intent = new Intent(MainActivity.this, NewActivity.class));
intent.putExtra("firstName",fvalue);
intent.putExtra("lastname",lname);
......
startActivity(intent);
NewActivity.java 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");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.