将内容从EditText传输到按钮上的另一个活动
我需要将EditText的内容传输到Button单击的其他活动。将内容从EditText传输到按钮上的另一个活动
这是我目前的新活动的启动代码:
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 ??????
}
});
}
的内容应该是在接下来的活动整数。
希望有人能帮助我。
最后一个问题:
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()
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侧写
Intent i = getIntent();
String var = i.getStringExtra("you_custom_variable_name");
int convert = Integer.parseInt(var);
很简单的方法
“you_custom_variable_name” - 我想我可以写任何我想要的东西(一些随机的狗屎)?或者它是我已经在某处指定的变量? – 2012-02-23 14:12:54
请点击标记以便其他用户可以很容易地找到 – 2012-02-23 14:16:13
我更喜欢勾号标记,当我确认它适用于我时:) – 2012-02-23 14:19:42
EditView中?你的意思是EditText? – m1ntf4n 2012-02-23 14:01:25
看到它是随机可变名,如果你直接传递任何变量即'String s = 10',那么写myIntent.putExtra(“you_custom_variable_name”,s);如果你传递任何随机的名字,像myIntent.putExtra(“you_custom_variable_name”,“name”); – 2012-02-23 14:15:15
do Intent i = getIntent(); – 2012-02-23 15:36:04