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