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

If you add andrid:clickable="true", your gridView will not preform click event, it will block all click events.

于 2015-07-16T06:19:27.593 回答