2010-04-11 110 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); 

我幾個紗廠一前一後這樣做必然,而且運作良好。