简体   繁体   English

如何保存并将超过5个Edit Text的值从一个活动转移到另一个活动?

[英]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.

相关问题 如何在android中将多个字符串从一个活动转移到另一个活动 - how to transfer more then one string from one activity to another in android 如何保存多个编辑文本框 - How can i save more than one edit text boxes 如何从列表视图检索编辑文本值到另一个活动? - How to retrieve the edit text value from list view to another activity? 无法编辑并将数据从一个活动保存到另一个活动 - Trouble edit and save data from one Activity to another Activity 如何将数据从一个活动转移到另一个活动? - How to transfer data from one activity to another? 如何将 int 类型全局变量的值从一个活动转移到另一个活动并在 textview 中显示? - How to transfer the value of a int type global variable from one activity to another activity and show it in textview? 从一项活动转移到另一项活动 - Transfer from one activity to another 如何从堆栈中相距一个以上的另一个活动返回我的主要活动? - How can I return to my main activity from another activity that is more than one away in the stack? 编辑文本值+警告对话框编辑文本值并将其保存到另一个活动 - Edit text value + alert dialog edit text value and save it to another activity 我无法将int值从一项活动转移到另一项活动 - I can't transfer int value from one activity to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM