【发布时间】:2013-10-03 07:44:13
【问题描述】:
我有一个问题,因为我无法在 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)
有人可以帮我吗?我没有找到解决方案。
最好的问候 {
【问题讨论】:
-
可能是因为您正在使用 WebView 覆盖整个项目。尝试在整个视图上设置 OnClickListener,而不是为 getView() 方法中的每个项目
-
感谢Carnal,现在我可以看到GridView 的项目被选中了,但是即使onItemClick 仍然不起作用。你能帮忙吗?问候
-
您可以在 getView() 方法中为每个膨胀项目设置 OnClick 而不是 OnItemClick 到每个“视图”。然后在 onClick 中,您可以执行通常在 onItemClick 中执行的操作...因为您在 getView() 中有位置,所以您知道您点击了哪个项目!
-
感谢 Carnal,我理解您的想法,但我想在另一个 Activity 中处理该位置,而不是在适配器中。我知道可以在 Activity 中定义静态方法,但这对 mi 应用程序不利。有什么建议吗?
-
我不太明白你的意思。处理另一个Activity中的位置?你能再解释一下吗?
标签: android gridview webview onitemclick