如何将Textview值设置为EditText

时间:2014-02-24 05:51:11

标签: android textview android-edittext

单击按钮时,如何将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"));

6 个答案:

答案 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);