2012-09-28 237 views
1

我有添加監聽器到微調器的問題。當我點擊一些微調項目時,什麼都沒有發生。這裏是我的代碼:Android微調監聽器

Button button_marker= (Button) findViewById(R.id.button_markers); 
    ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(this, R.array.markers, android.R.layout.simple_spinner_item); 
    spinner= new Spinner(this); 
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);  
    spinner.setAdapter(adapter); 

    button_marker.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      spinner.performClick(); 
     } 
    }); 

new AdapterView.OnItemSelectedListener() { 
     public void onItemSelected(AdapterView<?> arg0, View arg1, 
       int arg2, long arg3) { 
      Log.e("klkl", "klkl"); 

     } 

     public void onNothingSelected(AdapterView<?> arg0) { 
      Log.e("klkl", "klkl"); 


     } 
    }); 

回答

6
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 

      public void onItemSelected(AdapterView<?> arg0, View arg1, 
        int arg2, long arg3) { 
       Log.e("klkl", "klkl"); 

      } 

      public void onNothingSelected(AdapterView<?> arg0) { 
       Log.e("klkl", "klkl"); 

      } 
     }); 
0

嘗試使用

spinner .OnItemSelectedListener() { 

    public void onItemSelected(AdapterView<?> arg0, View arg1, 
      int arg2, long arg3) { 
     Log.e("klkl", "klkl"); 

    } 

    public void onNothingSelected(AdapterView<?> arg0) { 
     Log.e("klkl", "klkl"); 


    } 
}); 
0

您的微調進行點擊,而不是項目選擇。 試試這個:

spinner.setOnItemSelectedListener(new OnItemSelectedListener() { 
    public void onItemSelected(AdapterView<?> arg0, View arg1, 
      int arg2, long arg3) { 
     Log.e("klkl", "klkl"); 
    } 
    public void onNothingSelected(AdapterView<?> arg0) { 
     Log.e("klkl", "klkl"); 
    } 
});