2013-10-02 25 views
1

我遇到了问题,因为我无法捕获GridView中的OnItemClick事件(该项目有TextView和WebView)。我在GridView控件正确加载数据,但onItemClick不起作用这里是我的代码:带有WebView的Android GridView在OnItemClick事件中不起作用

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> 

和这部分代码在Activity中,并具有onItemClick部分

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

有人可以帮我吗?我找不到解决方案。

致以问候

回答

1

将以下属性添加到您的列表项的根布局。这将阻止项目中的事件:

android:descendantFocusability="blocksDescendants" 

例如,

<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" > 
+0

谢谢Szymon。但是,我不能让它工作。你能帮我吗? – user2316075

+0

对我来说就像一个魅力!太感谢了! –

相关问题