2012-03-27 70 views
0

我想從微調,我想然後將此項目存儲到一個數組,但目前我只是想知道如何可以得到當前選定的項目。下面是我目前的微調代碼,我在課堂上有許多微調。Android獲取選定的微調文本

Spinner session = (Spinner) findViewById(R.id.spinnerSession); 
    ArrayAdapter<CharSequence> adapterSession = ArrayAdapter.createFromResource(
      this, R.array.session_array, android.R.layout.simple_spinner_item); 
    adapterSession.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
    session.setAdapter(adapterSession); 

此微調框綁定到我的字符串文件中定義的數組。所以我想讓它得到用戶選擇的項目。

感謝

+0

看看這個(http://stackoverflow.com/questions/2652414/how-do-you-get-the-selected-value-of-a-spinner-android) – 2012-03-27 22:57:26

回答

0
public class MyOnItemSelectedListener implements OnItemSelectedListener { 

    public void onItemSelected(AdapterView<?> parent, 
     View view, int pos, long id) { 
     Toast.makeText(parent.getContext(), "The planet is " + 
      parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show(); 
    } 

    public void onNothingSelected(AdapterView parent) { 
     // Do nothing. 
    } 
} 

這是直接從開發者文檔在: http://developer.android.com/resources/tutorials/views/hello-spinner.html

基本上你需要實現微調的onItemSelectedListener。