Transfer content from EditText to another activity on buttonclick

ⅰ亾dé卋堺 提交于 2019-12-12 03:11:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!