单击按钮时,如何将Activity1 textview值设置为Activity2 edittext?
活性1
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Activity1.this, Activity2.class);
Bundle bundle = new Bundle();
bundle.putString("p",textview);
intent.putExtras(bundle);
startActivity(intent);
}
});
活性2
Bundle bundle = this.getIntent().getExtras();
EditText.setText(bundle.getString("p"));
答案 0 :(得分:4)
更改
bundle.putString("p",textview);
到
bundle.putString("p",textview.getText());
和
EditText.setText(bundle.getString("p"));
到
EditText editText = (EditText) findViewById(R.id.yourEditText)
editText.setText(bundle.getString("p"));
答案 1 :(得分:1)
您需要传递文本,而不是视图本身:
Intent intent = new Intent(Activity1.this, Activity2.class);
intent.putExtra("p", textview.getText());
startActivity(intent);
答案 2 :(得分:1)
实施Activity1
之类的
Intent intent = new Intent(Activity1.this, Activity2.class);
intent.putExtra("p", textview.getText());
startActivity(intent);
实施Activity2
之类的
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.balance);
Editext dt=(EditText)findViewByid(R.id.edittext);
Bundle bundle = this.getIntent().getExtras();
dt.setText(bundle.getString("p"));
}
答案 3 :(得分:0)
活性1
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Activity1.this, Activity2.class);
intent.putExtra("p",textview.getText());
startActivity(intent);
}
});
活性2
Intent intent = getIntent;
EditText eidtText = (EditText)findViewById(R.id.editTextId);
editText.setText(intent.getString("p"));
答案 4 :(得分:0)
尝试关注您的项目
<强>活性1 强>
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Intent intent = new Intent(Activity1.this, Activity2.class);
Bundle bundle = new Bundle();
bundle.putString("p",textview.getText().toString());
intent.putExtras(bundle);
startActivity(intent);
}
});
<强>活性2 强>
Bundle bundle = this.getIntent().getExtras();
EditText editText = (EditText) findViewById(R.id.your_editText)
editText.setText(bundle.getString("p"));
答案 5 :(得分:0)
试试如下:
在活动1
中Intent intent = new Intent(Activity1.this, Activity2.class);
intent .putString("p",textview.getText().toString());
startActivity(intent);
在活动2
中EditText editText = (EditText) findViewById(R.id.yourEditTextId);
String bundle = this.getIntent().getString("p");
editText.setText(bundle);