1

I have a problem because I can not capture the OnItemClick event in GridView (the item has a TextView and WebView). I load the data in GridView correctly but the onItemClick does not work Here is my code:

list_item_layout_redes.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/estilocasilla" >

<com.mhp.desarrollo.laycosandroid.CuadroImagenRed ======THIS IS A CLASS THAT EXTENDS   WEBVIEW
    android:id="@+id/imagen"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:scrollbars="none" />

<TextView
    android:id="@+id/texto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="#55000000"
    android:paddingBottom="15dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="15dp"
    android:textColor="@android:color/white"
    android:textStyle="bold" 
     android:clickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false"/>

activity_redes.xml

   <FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    .....

            <GridView
                android:id="@+id/gvRedes1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/grisMedio"
                android:cacheColorHint="#00000000"
                android:numColumns="2"
                android:textAlignment="textStart" >
            </GridView>
        ...
</FrameLayout>

and this part of code is in Activity and has onItemClick part

if (gvRedes1 != null) {
            gvRedes1.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> a, View v, int position,
                        long id) {

Somebody can I help me? I do not find a solution.

Best regards

user2316075
  • 479
  • 5
  • 16

1 Answers1

1

Add the following attribute to the root layout of your list item. This will block the events in the item:

android:descendantFocusability="blocksDescendants"

e.g.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="@drawable/estilocasilla"
     android:descendantFocusability="blocksDescendants" >
Szymon
  • 42,577
  • 16
  • 96
  • 114