In Android GridView, The onItemClick event cannot respond. androidgridview

Source: Internet
Author: User

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

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.