问题
I need to transfer the contents of an EditText to another activity on Button click.
This is my current code for start of new activity:
Button proceed;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.intro);
proceed = (Button) findViewById(R.id.bProceed);
proceed.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(Introscreen.this, BillardScoreboardActivity.class);
Introscreen.this.startActivity(myIntent);
myIntent.putExtra ??????
}
});
}
The contents are supposed to be integers in the next activity.
Hope someone can help me.
Final problem:
Intent i = getIntent() //Error message if ";" isn't put after getintent()
String var = i.getStringExtra("lol");
int convert = Integer.parseInt(var); //Error message if ";" is put after getIntent()
回答1:
EdiText ed = (EditText)findViewById(R.id.editText);
String s = ed.getText.toString();
public void onClick(View v)
{
Intent myIntent = new Intent(Introscreen.this, BillardScoreboardActivity.class);
myIntent.putExtra("you_custom_variable_name",s);
startActivity(myIntent);
}
Reveiver Side Write
Intent i = getIntent();
String var = i.getStringExtra("you_custom_variable_name");
int convert = Integer.parseInt(var);
THis is Simple Method
来源:https://stackoverflow.com/questions/9414477/transfer-content-from-edittext-to-another-activity-on-buttonclick