我试图在一个活动(activity1)中的android中的EditTexts中接收两个输入。这两个输入是一个表的维度,我在另一个活动(activity2)中动态创建。我尝试使用Bundles以及简单的意图。我正在接受一个维度而无法收到另一个维度。第二维自动获取第一维的值。
如何在android中发送和接收多个值。请帮忙。
我的第一项活动如下
public final static String EXTRA_MESSAGE = "abc";
public final static String EXTRA_MESSAGE2 = "abc";
Intent intent = new Intent( c , CreateTimeTable.class);
Bundle bun = new Bundle();
EditText editText = (EditText) findViewById(R.id.nlec);
EditText editText2 = (EditText) findViewById(R.id.nday);
String message = editText.getText().toString();
String message2 = editText2.getText().toString();
bun.putString(EXTRA_MESSAGE, message);
bun.putString(EXTRA_MESSAGE2, message2);
intent.putExtras(bun);
startActivity(intent);
第二项活动是
setContentView(R.layout.activity_create_time_table);
int j;
Intent intent = getIntent();
Bundle bun = this.getIntent().getExtras();
String message = bun.getString(NewTT.EXTRA_MESSAGE);
String message2 = bun.getString(NewTT.EXTRA_MESSAGE2);
int lec = Integer.parseInt(message);
int day = Integer.parseInt(message2);
变量lec获取与日相同的值,无论输入是什么
答案 0 :(得分:2)
Intent intent= new Intent(YourActivity.this, SecondActivity.class);
intent.putExtra("key1", valuetopass_1);
intent.putExtra("key2", valuetopass_2);
startActivity(intent);
// Get values in second activity
Intent in = getIntent();
String value1 = in.getStringExtra("key1");
String value2 = in.getStringExtra("key2");
答案 1 :(得分:1)
Intent myIntent = new Intent(mycurentActivity.this, secondActivity.class);
myIntent.putExtra("key", myEditText1.Text.toString());
myIntent.putExtra("key1", myEditText2.Text.toString());
myIntent.putExtra("key2", myEditText3.Text.toString());
startActivity(myIntent);
String text = myIntent.getStringExtra("key1");
String text1 = myIntent.getStringExtra("key2");
String text3 = myIntent.getStringExtra("key");
答案 2 :(得分:1)
public final static String EXTRA_MESSAGE = "abc";
public final static String EXTRA_MESSAGE2 = "abc";
变量lec获取与日相同的值,无论输入是什么
键是相同的,所以值是相同的。使密钥不同。
答案 3 :(得分:0)
发送意图时:
intent.putExtra("YOUR-KEY_1", "data_here");
intent.putExtra("YOUR-KEY_2", "data_here");
收到意图时:
if(getIntents()!= null){
String data1 = getIntents().getExtras().getString("YOUR-KEY_1");
String data2 = getIntents().getExtras().getString("YOUR-KEY_2");
}
就是这样! :)