2012-03-27 10 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) –

答えて

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を実装する必要があります。

関連する問題