0
我有一个问题,因为我无法捕获GridView中的OnItemClick事件(该项目有一个TextView和WebView)。我在GridView控件正确加载数据,但onItemClick不起作用这里是我的代码:Android的OnItemClick事件不适用于GridView白色的WebView和文本
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>
和这部分代码在活动并已onItemClick部分
if (gvRedes1 != null) {
gvRedes1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position,
long id)
有人可以帮我吗?我找不到解决方案。
问候 {
也许是因为你正在用你的WebView覆盖整个项目。尝试在整个视图中设置一个OnClickListener,而不是为getView()方法中的每个项目设置 – Carnal
谢谢Carnal,现在我可以看到GridView的项目被选中,但即使onItemClick仍然不起作用。你能帮助吗?问候 – user2316075
您可以将OnClick而不是OnItemClick设置为getView()方法中每个充气项目的每个“视图”。然后在onClick中,你可以做你通常会在onItemClick中做的事情......因为你在getView()中有位置,所以你知道你点击了哪个项目! – Carnal