[英]How to save and transfer the value of more than 5 edit Text from one activity to another?
I want to transfer between activities the data that i edit in my EditText fields. 我想在活动之间传输在EditText字段中编辑的数据。 If i transfer from activity 1 to activity 2 i want to be able in activity 2 to edit the data that i received from activity 1, to save the new data in the activity 2 and transfer to the activity 3. How can i save and transfer the data in the same time. 如果我从活动1转移到活动2,我希望能够在活动2中编辑我从活动1接收的数据,以将新数据保存在活动2中并转移到活动3。我如何保存和转移数据在同一时间。 Now with shared preferences i can tranfer but i can't save the data that i just edit in the current activity. 现在,有了共享的首选项,我可以进行转移,但是我无法保存我在当前活动中刚刚编辑的数据。 Please Help! 请帮忙! Thank you! 谢谢!
this is the code used to save the weight in Activity 1 (WEEK1): 这是用于在活动1(WEEK1)中减轻重量的代码:
SharedPreferences WeightPreferences = getSharedPreferences("WEEK1", MODE_PRIVATE);
String r1 = w1.getText().toString();
String r2 = w2.getText().toString();
String r3 = w3.getText().toString();
String r4 = w4.getText().toString();
String r5 = w5.getText().toString();
SharedPreferences.Editor editor = WeightPreferences.edit();
editor.putString("wr1", r1);
editor.putString("wr2", r2);
editor.putString("wr3", r3);
editor.putString("wr4", r4);
editor.putString("wr5", r5);
editor.commit();
This is the code used to show the weights from Activity 1 in Activity 2 (WEEK2) and so on: 这是用于显示活动2(WEEK2)中活动1的权重的代码,依此类推:
SharedPreferences WeightPreferences = getSharedPreferences("WEEK1", MODE_PRIVATE);
String string1 = weightPreferences.getString("wr1", null);
String string2 = weightPreferences.getString("wr2", null);
String string3 = weightPreferences.getString("wr3", null);
String string4 = weightPreferences.getString("wr4", null);
String string5 = weightPreferences.getString("wr5", null);
w1.setText(string1);
w2.setText(string2);
w3.setText(string3);
w4.setText(string4);
w5.setText(string5);
You can create a arraylist with all your data and transfer the object to the calling event using 您可以使用所有数据创建一个arraylist,然后使用将该对象转移到调用事件
intent.putExtra("Name", Object_with_all_your_content);
Did I understand your question? 我明白你的问题吗?
Put the values into an array and send it like this : 将值放入数组中,然后像这样发送:
To send : 发送 :
Intent intent =new Intent(ccurrentClass.this, anotherClass.class);
Bundle b = new Bundle();
b.putSerializable("value", arrayOfString);
intent.putExtras(b);
startActivity(intent);
TO retrieve : 检索:
Intent intent = getIntent();
Bundle b = intent.getExtras();
String[][] data = (String[][]) b.getSerializable("value");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.