【问题标题】:Android GridView with WebView does not work in OnItemClick Event带有 WebView 的 Android GridView 在 OnItemClick 事件中不起作用
【发布时间】:2013-10-02 23:14:53
【问题描述】:

我有一个问题,因为我无法在 GridView 中捕获 OnItemClick 事件(该项目具有 TextView 和 WebView)。我在 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) {

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

最好的问候

【问题讨论】:

    标签: android gridview webview onitemclick


    【解决方案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" >
    

    【讨论】:

    • 谢谢希蒙。但我不能让它工作。你能帮帮我吗?
    猜你喜欢
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-06
    • 2014-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多