0

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) 

誰か助けてくれませんか?解決策が見つかりません。

よろしくお願いします {

4

1 に答える 1

0

以下をActivity作成しますListener

public interface GridListener{

    public void onItemClicked(int position);

}

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

    }
};

次に、次のような方法でActivityこれをアダプターに追加します。Listener

gvRedes1.setOnGridListener(gridListener);

上記で作成したこのリスナーを入力として受け取るアダプターでメソッドを作成し、アダプタークラスにあるsetOnGridListenerインスタンスクラスに入力を設定するGridListener必要があります。何かのようなもの:

private GridListener gridListener;
public void setOnGridListener(GridListener listener){
    gridListener = listener;
} 

onClickアダプターで、私が提案したようにinを使用してアイテムをクリックするgetView()と、このリスナーで次のようにコールバックを作成できますActivity

gridListener.onItemClicked(position);
于 2013-10-04T08:18:45.840 に答える