Android GridView button Click event Onitemclick not responding

Source: Internet
Author: User

Today in a similar to Baidu post-paste things. Layout: Above is a actionbar title bar, and then a GridView layout, in the Java code to dynamically load the attention of the stick, all ready, very happy to fix it!

Now you need to click on the option to enter a bar, then the problem is--gridview button Click event Onitemclick cannot respond.


So, the main trick is still in the Com.android.internal.r.attr.buttonstyle, look at this XML file, button set two more properties as follows:
<item name= "Android:focusable" >true</item>
<item name= "Android:clickable" >true</item>
So we have to set these two properties to false in the code, so that we can respond to the Onitemclick method of the GridView, but be aware that, whether it is a button or a textview, as long as the onclick () is set, Then Onitemclick () will not be executed (the above is based on a GridView or the ListView of each item only one item, but if the button, if not TextView, not the case, it can only refer to the above).

Solution : (Modify the button XML layout) plus the following two is OK ...

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 Set button will not respond to Onitemclick (), http://www.cnblogs.com/zgz345/archive/2012/07 /05/2578110.html

Android GridView button Click event Onitemclick not responding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.