Android GridView does not respond after setting the button Onitemclick ()

Source: Internet
Author: User

when we set the Textiew in the GridView or the ListView, if we don't set Onlick () to Textiew, then Gridiew's Onitemclick () can be executed, But when we change the TextView to a button we don't set the OnClick (), the Onitemclick () of the GridView is also not enforceable, for what, it shows that there is a difference between the button and the TextView internal event, To see the source code of the button, the code is very few .
Public class Button extends TextView {
Public Button (context context) {
This (context, NULL);
    }

Public Button (context context, AttributeSet attrs) {
This (context, attrs, com.android.internal.r.attr.buttonstyle);
    }

Public Button (context context, AttributeSet attrs, int defstyle) {
Super (context, attrs, defstyle);
    }
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, if not the button, but TextView, not the case, the above can only refer to it)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android GridView does not respond after setting the button Onitemclick ()

Related Article

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.