我有四个EditText
值。我存储SharedPreferences
用于稍后获取的值。存储后,我需要通过单击微调器获取这些值。我搜索了一些文件,但不是很清楚。我只需要从edittext中获取et值,如果我在edittext中重新输入另一个值,我需要用2个按钮增加微调器值。
代码:
活动:
final Map<String, String> demomap = new HashMap<String, String>();
demomap.put(et.getText().toString(), et1.getText().toString());
demomap.put(et2.getText().toString(), et3.getText().toString());
SharedPreferences preferences = getSharedPreferences("CREATE_MEAL",
0);
SharedPreferences.Editor editor = preferences.edit();
for (Entry<String, String> entry : demomap.entrySet()) {
editor.putString(entry.getKey(), entry.getValue());
}
editor.commit();
活动一:
spinner = (Spinner)findViewById(R.id.spinner1);
demomap = new HashMap<String, String>();
SharedPreferences preferences = getSharedPreferences("CREATE_MEAL", 0);
for (Entry<String, ?> entry : preferences.getAll().entrySet()) {
demomap.put(entry.getKey(), entry.getValue().toString());
}
Iterator myVeryOwnIterator = demomap.keySet().iterator();
while (myVeryOwnIterator.hasNext()) {
String key = (String) myVeryOwnIterator.next();
String value = (String) demomap.get(key);
spinner.setText(value);
}