Spinner 使用细节

使用Spinner在setOnItemClickListener时抛出RuntimeException 
      Spinner s = (Spinner) findViewById(R.id.spinner);
      s.setOnItemClickListener(new AdapterView.OnItemClickListener(){

        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            
        }});

public void setOnItemClickListener(AdapterView.OnItemClickListener I)
    Spinner不支持item的点击事件,调用此方法将引发异常。
参数
  l        这个监听将被忽略

 

public class ImageView1Activity extends Activity { 
    /** Called when the activity is first created. */ 
    private Spinner spinner1 = null; 
    private ArrayAdapter<CharSequence> adapter = null; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
        spinner1 = (Spinner)findViewById(R.id.spinner1); 
        spinner1.setPrompt("你要以后在哪工作?"); 
        adapter = ArrayAdapter.createFromResource(this,R.array.city,android.R.layout.simple_spinner_item); 
        spinner1.setAdapter(adapter); 
         
        spinner1.setOnItemSelectedListener(new OnItemSelectedListener() { 
 
            public void onItemSelected(AdapterView<?> arg0, View arg1, 
                    int arg2, long arg3) { 
                // TODO Auto-generated method stub 
 
                Toast.makeText(ImageView1Activity.this,"选择的城市是:" +spinner1.getItemAtPosition(arg2).toString(), Toast.LENGTH_LONG).show(); 
 
            } 
 
            public void onNothingSelected(AdapterView<?> arg0) { 
                // TODO Auto-generated method stub 
                 
            } 
             
        }); 
    } 
}   


} Spinner 使用细节

 

你可能感兴趣的:(Spinner 使用细节)