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);
Run Code Online (Sandbox Code Playgroud)
从使用上面的代码我可以获得其他活动的字符串值,但我需要editText另一个活动的对象.
有谁可以给出想法?
谢谢
为什么不发送ID然后在接收器Activity上使用findViewByid()?希望这可以帮助:
Intent intent = new Intent();
String name="textView";
int value=EditText.getID();
intent.putExtra(name, value);
setResult(RESULT_OK, intent);
Run Code Online (Sandbox Code Playgroud)
关于接收器活动:
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");
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6159 次 |
| 最近记录: |