【发布时间】:2018-02-19 14:07:12
【问题描述】:
Here is screenshot ...my changes in spinner value reflects only after 2 swipes 我有一个有 10 个屏幕的应用程序,我的主要活动中有 1 个微调器,片段中有一个文本框。我想在我的文本框中显示最近选择的微调器值。
我编写了一个代码来在我的文本框中显示选定的微调器值,并且它在我的所有屏幕中都变得稳定。但我不知道如何根据最近选择的微调器值动态更改文本框值。 (在投反对票之前,请给我一些解决方案)
这是获取微调器值的代码
String pos = (String) spinner.getSelectedItem();
SharedPreferences sharedPref = getSharedPreferences("Mode", Activity.MODE_PRIVATE);
SharedPreferences.Editor prefEditor = sharedPref.edit();
prefEditor.putString("userChoicemode", pos);
prefEditor.commit();
这是检索它的代码
TextView modeselect = (TextView) view.findViewById(R.id.pass);
SharedPreferences sharedPref = this.getActivity().getSharedPreferences("Mode", Activity.MODE_PRIVATE);
String get = sharedPref.getString("userChoicemode",selected);
modeselect.setText("" + get);
【问题讨论】:
-
只调用spinner的onselecteditem方法
-
你能解释一下它是如何工作的..??动态的..??
-
我已经在回答中解释过了,请仔细阅读
标签: java android dynamic spinner