Android OnItemClick事件在带有WebView和文本的GridView中不起作用

Android OnItemClick事件在带有WebView和文本的GridView中不起作用,android,gridview,webview,onitemclick,Android,Gridview,Webview,Onitemclick,我有一个问题,因为我无法在GridView中捕获OnItemClick事件(该项具有TextView和WebView)。我在GridView中正确加载了数据,但onItemClick不起作用。这是我的代码: 列表\项目\布局\ redes.xml <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:lay

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

列表\项目\布局\ 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"/>
 <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_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"/>
 <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>

.....
...
这部分代码处于活动状态,并且具有mclick部分

if (gvRedes1 != null) {
            gvRedes1.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> a, View v, int position,
                        long id) 
if(gvRedes1!=null){
gvRedes1.setOnItemClickListener(新的OnItemClickListener(){
公共视图单击(适配器视图a、视图v、内部位置、,
长id)
有人能帮我吗?我找不到解决办法

致意
{

活动中
创建以下
侦听器

public interface GridListener{

    public void onItemClicked(int position);

}

private GridListener gridListener = new XMPPConnectionListener() {
    @Override
    public void onItemClicked(int position) {

    }
};
然后在
活动中
以如下方式将此
侦听器
添加到适配器:

gvRedes1.setOnGridListener(gridListener);
您需要在适配器中创建方法
setOnGridListener
,该方法将上面创建的侦听器作为输入,并将输入设置为适配器类中的实例类
GridListener
。类似于:

private GridListener gridListener;
public void setOnGridListener(GridListener listener){
    gridListener = listener;
} 
现在,在适配器中,当您按照我的建议使用
getView()
中的
onClick
单击某个项目时,您可以使用此侦听器回调您的
活动

gridListener.onItemClicked(position);

可能是因为您正在使用WebView覆盖整个项目。请尝试在整个视图中为getView()方法中的每个项目设置OnClickListener。感谢Carnal,现在我可以看到GridView的项目已被选中,但即使onItemClick仍不起作用。您能提供帮助吗?Regard您可以将OnClick not onItemClick设置为each在getView()方法中为每个膨胀的项目设置“视图”。然后在onClick中,您可以执行通常在onItemClick中执行的操作…因为您在getView()中有位置你知道你点击了哪个项目!谢谢Carnal,我理解你的想法,但我想在另一个活动中处理该职位,而不是在Adapter中。我知道可以在活动中定义静态方法,但这对mi应用程序不好。有什么建议吗?我不太明白你的意思。在另一个活动中处理该职位?你能体验一下吗多躺一会儿?