下午好,
我有一个包含 3 个微调器的微调器数组。每个微调器都通过一个 res 字符串数组填充。每个数组包含数字 1-100。当 Activity 开始时,每个微调器都包含一个 1-100 的字符串数组,当您单击微调器时,第一个选择是 1。
假设用户在第一个微调器上选择了 25。我希望第二个微调器在单击微调器但不触发微调器时显示 25 作为滚动的起点。第二个微调器仍将包含数组 1-100,因此用户可以根据需要向下滚动到房东编号。
我尝试过使用 setSelection,但这会导致第二个微调器触发,从而导致不良影响(即使用户没有单击第二个微调器,编辑框也会填充第二个数字)。我希望第二个微调器只显示 25 作为起点。
我该怎么做?
最佳答案
setSelection()
是我所知道的唯一方法,它不应该是问题的原因。
就我而言,我有:
Spinner spinner = new Spinner(getApplicationContext());
spinner = (Spinner) findViewById(R.id.spinner);
//search for the position that we need to move to,
//the spinner has an array adapter set to it
int recordInPreferences = WidgetProvider.settings.getInt("SpinnerChoice", 0);
int counter = -1;
do {
counter++;
} while (
counter < getResources().getIntArray(R.array.stringofvalues).length &&
getResources().getIntArray(R.array.stringofvalues)[counter] != recordInPreferences
);
spinner.setSelection(counter, true);
我对几个微调器一个接一个地执行此操作,效果很好。
关于android - 在微调器中设置位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2618650/