1

下午好,

我有一个包含 3 个微调器的微调器数组。每个微调器都通过 res 字符串数组填充。每个数组包含数字 1-100。当活动开始时,每个微调器都包含一个 1-100 的字符串数组,当您单击微调器时,第一个选择是 1。

假设用户在第一个微调器上选择了 25。我希望第二个微调器在单击微调器但不触发微调器时显示 25 作为滚动的起点。不过,第二个微调器仍将包含数组 1-100,因此用户可以根据需要向下滚动到出租人编号。

我尝试使用 setSelection 但这会导致第二个微调器触发,从而导致不良影响(即使用户没有单击第二个微调器,编辑框也会填充第二个数字)。我希望第二个微调器只显示 25 作为起点。

我该怎么做呢?

4

1 回答 1

2

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);

我依次为几个微调器执行此操作,并且效果很好。

于 2011-01-10T10:38:59.820 回答