如何通过的EditText到另一个活动? [英] How to pass EditText to another activity?
本文介绍了如何通过的EditText到另一个活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Intent intent = new Intent(this,Name.class);
intent.putExtra("key", et.getText().toString());
startActivity(intent);
Intent intent = getIntent();
String str = intent.getStringExtra("key");
tv.setText(str);
使用上述code我可以在其他活动的字符串值,但我需要 EDITTEXT
对象在另一个活动。
From using above code I can get a string value at other activity, but I need editText
object at another activity.
谁能给想法?
感谢
推荐答案
为什么不发送的ID,然后在接收器上活动使用findViewByid()?希望这有助于:
Why not send the ID and then use findViewByid() on the receiver Activity? Hope this helps:
Intent intent = new Intent();
String name="textView";
int value=EditText.getID();
intent.putExtra(name, value);
setResult(RESULT_OK, intent);
在接收活动:
private static final int REQUEST_CODE=1;
private int id;
private EditText et;
private Intent i;
i = new Intent(this,Name.class);
startActivityForResult(intent, REQUEST_CODE);
et = (EditText)findViewById(id);
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE)
{
if (data.hasExtra("textView"))
{
//Get the selected file.
id = data.getExtras().getInt("textView");
}
}
}
这篇关于如何通过的EditText到另一个活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文