GridView.setOnItemClickListener is not working

社会主义新天地 提交于 2019-12-04 05:18:12

I think your ImageViews stealing Focus because they are Checkable. So the item click doesnt happen because your ImageViews intercepting it.

Adding these attributes to your imageviews might help but probably could trouble your checkings.

    android:focusable="false"
    android:focusableInTouchMode="false"

Having checkable items in a listview is bit of pain. But i think you will find related topics how to do it.

Here is 1 tutorial that seems suitable, i admit i didnt threw a closer look on it but you might want to:

http://windrealm.org/tutorials/android/listview-with-checkboxes-without-listactivity.php

Also make sure, that your Adapter returns true for isEnabled

@Override
     public boolean isEnabled(int i) {
     return true;
}

http://developer.android.com/reference/android/widget/BaseAdapter.html#isEnabled(int)

isEnabled(int position) Returns true if the item at the specified position is not a separator.

Otherwise the click event, will not be throw for your item

Hope this may help someone, In gridview, if you add buttons or set "android:clickable=true" in the element inside it, gridview's OnItemClickListener will not be listened, instead you can create an Image or TextView with image and see to that you have not set the clickable="true". Now, the OnItemClickListener will listen to the TextView and this worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!