我想在editText1(Activity1)中输入相同的文本到editText2(Activity2)
在活动 1 中:
public class Activity1 extends Activity {
editText1 = (EditText) findViewById(R.id.editText1);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all1);
}
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()) {
case R.id.settings:
Intent intent = new Intent(Activity1.this, Activity2.class);
intent.putExtra("editTextentered", editText1.getText().toString());
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
在活动 2 中:
public class Activity2 extends Activity {
private EditText editText1;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
editText1 = (EditText) findViewById(R.id.editText2);
setContentView(R.layout.settings);
Bundle extras = getIntent().getExtras();
String editTextentered = null;
if(extras !=null && extras.containsKey("editTextentered")) {
editTextVal= extras.getString("editTextentered");
}
editText1.setText(""+editTextentered);
}
}
我正在尝试调试应用程序,但是它崩溃了