How to get Spinner selected item value to string?

前端 未结 14 2015
离开以前
离开以前 2020-12-02 18:18

I have 5 Spinners. In order to make it summary to this.

This is Spinner in xml



        
14条回答
  •  甜味超标
    2020-12-02 18:49

    If your Spinner was populated by SQLite cursor, then the solution is:

    Spinner mySpin = (Spinner) findViewById(R.id.myspin);
    mySpin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {  
    @Override
    public void onItemSelected(AdapterView parent, View view, int position, long id) {
               SQLiteCursor item = (SQLiteCursor) parent.getItemAtPosition(position);
               String value = String.valueOf(item.getString(0));
               Toast.makeText(getApplicationContext(), "The option is:" + value , Toast.LENGTH_SHORT).show(); 
     }
    

    PS: In item.getString(0) -> 0 is the index of column on cursor that you want to get.

提交回复
热议问题