Sonu Sonu - 5 months ago 21
Android Question

setOnItemClickListener Not Works with Spinner

setOnItemClickListener Not Works with Spinner. Here is my code...

supplier.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub

String msupplier=supplier.getSelectedItem().toString();
Log.e("Selected item : ",msupplier);

}
});

Answer

setOnItemClickListener will not works with spinner. Try using this method:

setOnItemSelectedListener

Change your code like following:

supplier.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                // TODO Auto-generated method stub
                String msupplier=supplier.getSelectedItem().toString();

                Log.e("Selected item : ",msupplier);
}

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub

            }
        });