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);
}
});
1. I think you should check your xml file which contains the spinner. Make sure haven't set
android:clickable = "false"
.2. please check your spinner adapter and make sure in your
getView(int position, View convertView, ViewGroup parent)
method, you haven't set any widget click callback event such asButton
,Imageview
,TextView
i have faced this issues. setOnItemClickListener will not works with spinner. My solution is as following:
Use getItemAtPosition:
setOnItemClickListener will not works with spinner. Try using this method:
Change your code like following:
Use this
OnItemSelectedListener()
serves a different purpose than a click listener. Most importantly, it doesn't fire if you click on the currently selected item again. In some cases this might not be a problem but in other cases, it might well be. So the real answer is not to tell people to use a different and probably unsuitable listener but to solve the original problem. :-)Fortunately, we can place the click listener on the adapter instead:
and then we can use it as usual, with the only difference of not setting it on the spinner but on the adapter instead: