2014-04-09 122 views
0
public class uploadActivity extends Activity implements OnClickListener { 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     Spinner spinner = (Spinner) findViewById(R.id.spinner_list); 

     // Create an ArrayAdapter using the string array and a default spinner layout 
     ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, 
     R.array.spinner_arrays, 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); 
    } 

     public void onItemSelected(AdapterView<?> parent, View view, 
     int pos, long id) { 
    Toast.makeText(parent.getContext(), "Selected entry in spinner is : " +  parent.getItemAtPosition(pos).toString(), Toast.LENGTH_SHORT).show(); 
} 

     public void onNothingSelected(AdapterView<?> parent) { 

} 

}如何在沒有實現的情況下在android中實現微調器?

我試圖微調添加到我的課堂活動,但在我的項目有4個按鈕,對,我需要OnClickListener來實現,我已經完成了它的功能,所以我不能改變onclicklistener到OnItemSelectedListener和即時嘗試波紋管方法,但因爲我沒有實現OnItemSelectedListener。像onItemSelected方法不叫當我點擊入境因此如何在DIS情況下

感謝執行

回答

2

試試這個..

spinner.setOnItemSelectedListener(new OnItemSelectedListener() { 
     @Override 
     public void onItemSelected(AdapterView<?> arg0, View v, 
       int position, long id) { 
      Log.v("SpinnerSelected Item", 
        "" + spinner.getSelectedItem()); 
      Log.v("Clicked position",""+position); 
     } 

     @Override 
     public void onNothingSelected(AdapterView<?> arg0) { 
      Log.v("NothingSelected Item", 
        "" + spinner.getSelectedItem()); 
     } 
    }); 

或者,您可以使用如下

public class uploadActivity extends Activity implements OnClickListener,OnItemSelectedListener{ 
+0

可以嗎?如何爲每個條目分配值? – andy

+0

喜歡在列表中有人說遊戲,家庭,時尚條目,當我點擊任何一個條目從微調[說遊戲]我想返回一些價值,如遊戲返回值1和家庭2和時尚3等 – andy

+1

@andy在'onItemSelected'裏面的位置變量裏面會返回值1,2,3等, – Hariharan

相關問題