2012-08-14 22 views
-1

至於儀式現在我只有一個微調有三​​個選項,我想要做的是如果選項一被選中,然後從list1中隨機選擇,選項2從列表2中選擇等等,我有一個小部分代碼寫得足以宣告微調和填充選擇,我從哪裏去?感謝提前!你如何從不同的名單中挑選一個微調器?

這裏是我的xml我的代碼:

<Spinner 
    android:id="@+id/alcohol" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dp" 
    android:prompt="@string/prompt" /> 

然後,這是我的java文件:

setContentView(R.layout.activity_options); 
// Set Alcohol Spinner 
    Spinner spinner = (Spinner) findViewById(R.id.alcohol); 
// Create an ArrayAdapter using the string array and a default spinner layout 
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, 
     R.array.alcohol, android.R.layout.simple_spinner_item); 
// Specify the layout to use when the list of choices appears 
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
// Apply the adapter to the spinner 
spinner.setAdapter(adapter); 

謝謝大家!

回答

1

我想你需要從spinner中選擇物品。如果是這樣,那麼試試這個。微調的

spinner.setOnItemSelectedListener(new listener_Of_spinner()); 

//監聽器實現用於選擇客房

public static class listener_Of_spinner implements OnItemSelectedListener 
{ static String getSelectedItem; 
    public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) 
    { 
     // By using this you can get the position of item which you have selected from the dropdown 
     getSelectedItem = (parent.getItemAtPosition(pos)).toString(); 
    } 
    public void onNothingSelected(AdapterView<?> parent) 
    {   
     // Do nothing. 
    } 
}; 

希望這可能是有用的

相關問題