2014-02-24 123 views
-1

如何設置的活動1的TextView值活性2的EditText當我點擊按鈕?如何TextView的值設置爲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")); 
+3

你,你只需要創建對象的EditText第一 –

+0

這個問題似乎是題外話,因爲它的問題大約最小的理解正確的方式。 – GrIsHu

回答

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

您需要通過文本,而不是視圖本身:

Intent intent = new Intent(Activity1.this, Activity2.class); 
intent.putExtra("p", textview.getText()); 
startActivity(intent); 
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")); 
     } 
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")); 
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")); 
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);