2017-04-04 91 views
0

我正在使用MaterialBetterSpinner。
如何獲取選定的項目文本或位置?如何獲取MaterialBetterSpinner中選定的項目文本或位置?

每次我得到相同的標誌。
我該怎麼辦?

我想把這個標誌發送到服務器並根據它得到響應。
每次發送flag_check=1;

ArrayList<String> morning_evening_flag = new  ArrayList <String>(); 


       morning_evening_flag.add("Morning"); 
       morning_evening_flag.add("Evening"); 

ArrayAdapter<String> spinnerAdapter1 = new ArrayAdapter<String>(context,R.layout.spinner_row, morning_evening_flag); 
        final MaterialBetterSpinner spinner1 = (MaterialBetterSpinner) dialogView.findViewById(R.id.spinner1); 
        spinner1.setAdapter(spinnerAdapter1); 
          int morning_pasition=spinnerAdapter1.getPosition("Morning"); 

       int Evening_pasition=spinnerAdapter1.getPosition("Evening"); 

       Log.e("morning_pasition", morning_pasition+""); 
       Log.e("Evening_pasition", Evening_pasition+""); 
       final int flag_check; 
       if("Morning".equals("0")) 
       { 
        flag_check=0; 
       } 
       else 
        flag_check=1; 

回答

0

您需要的onClickListener設置微調爲:

spinnerName.setOnItemSelectedListener(本);

而現在實現onItemselected方法

@Override 
public void onItemSelected(AdapterView<?> parent, View view, int position, 
     long id) { 
    // You will get the position and selected item here 
} 
相關問題