2010-04-11 70 views
1

下午好,设置微调内的位置

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

说一个用户在第一个微调器上选择25。我希望第二个微调器显示25为微调旋钮时点击滚动的起点,但不能触发微调器。第二个微调器仍然会包含数组1-100,但是如果用户想要,用户可以向下滚动到出租者号码。

我试过使用setSelection,但导致第二个微调起火造成不良影响(即使用户没有点击第二个微调框,编辑框用第二个数字填充)。我希望第二名微调者仅以25为出发点。

我该怎么做?

回答

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

我几个纱厂一前一后这样做必然,而且运作良好。