0

アプリに次の項目レイアウトの GridView があります。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" 
    android:background="@android:drawable/list_selector_background" >

    <TextView
            android:id="@+id/notizenTitel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Titel"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textStyle="bold" />

    <TextView
        android:id="@+id/notizenBeschreibung"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Beschreibung" />
</LinearLayout>

ユーザーがクリックした場合にアイテムを選択したいと思います。私はこのコードで試しました:

gv.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE);
gv.setOnItemClickListener(this);

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
    GridView gv = (GridView) getView().findViewById(R.id.notizenGrid);
    gv.setSelection(position);
    adapter.notifyDataSetChanged();
}

しかし、アイテムをクリックすると、背景がすぐに黄色に変わり、消えます。そのため、アイテムをクリックしている間はセレクターが機能しますが、選択はできません。理由はありますか?

4

2 に答える 2

1

線形レイアウトでプロパティを追加する

アンドロイド:クリッカブル = "真"

それが役立ちます。

于 2014-02-24T13:22:44.617 に答える
0

を追加する andrid:clickable="true"と、gridView はクリック イベントを実行せず、すべてのクリック イベントをブロックします。

于 2015-07-16T06:19:27.593 に答える