好的..我有2节课: -
1. Apple.class
2. Banana.class
和2.XML文件: -
1. ear.xml
2. nose.xml
现在,我想在apple.class
中添加一个编辑文本框
但我想打印用户在banana.class
输入的文本
1)通过以下方式从edittext获取输入的值
String content = EditText.getText().toString();
2)然后使用Intent将字符串“content”传递给下一个Activity。
Intent i = new Intent(Apple.this,Banana.class);
i.putstring("EditTextValue",content);
startactivity(i);
3)获取Banana类中的数据并设置为textview。
单击按钮时使用以下代码,将数据从AppleActivity发送到BananaActivty:
String value = edittext.getText().toString().trim(); //get text from editText
Intent i=new Intent(FirstDemo.this,SecondDemo.class);
i.putExtra("key", value);//you can add other key value
startActivity(i);
那么在其他课程中你必须从Intent获得价值,如下所示:
String value = getIntent().getStringExtra("key"));
希望对你有用
//one activity(FirstDemo)
EditText ed1,ed2;
String st="",st2="";
//onCreate method:-
st=ed1.getText().toString().trim();
st2=ed2.getText().toString().trim();
//then click on button
Intent i=new Intent(FirstDemo.this,SecondDemo.class);
i.putExtra("id", st);
i.putExtra("u_email", st2);
startActivity(i);
//then next Activity(SecondDemo):-
Edittext e1,e2;
Intent j = getIntent();
e1.setText(j.getStringExtra("id"));
e2.setText(j.getStringExtra("u_email"));