In Android GridView, The onItemClick event cannot respond. androidgridview
Today, I am playing with something similar to Baidu posts. Layout: The above is an ActionBar title bar, and then a GridView layout. Load the attention post dynamically in the Java code. Everything is ready, and it is very pleasant!
Now you need to click the option to enter a post. The problem is that the onItemClick event of the Button in the GridView cannot respond.
Therefore, we can check the xml file in com. android. internal. R. attr. buttonStyle. The Button has two more attributes:
<Item name = "android: focusable"> true </item>
<Item name = "android: clickable"> true </item>
Therefore, we need to set these two attributes to false in the code so that we can respond to the onItemClick method of the GridView. However, we must note that whether it is Button or TextView, as long as onClick () is set, OnItemClick () will not be executed (the above content is only one Item based on a GridView or ListView, if it is not a Button or TextView, this is not the case, the above can only be referenced ).
Solution(Modify the Button XML layout) Add the following two to make it okay ......
Android: focusable = "false"
Android: clickable = "false"
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"> <Button android:layout_width="match_parent"android:layout_height="match_parent"android:focusable="false"android:clickable="false" android:id="@+id/btn_spot" android:text="" /></LinearLayout>
Reference: zgz345 blog Park, Android GridView after setting the Button can not respond to OnItemClick (), http://www.cnblogs.com/zgz345/archive/2012/07/05/2578110.html