在CAB Android的持续gridview的选择CAB、Android、gridview

2023-09-07 10:29:38 作者:有妳〆很幸福

我在使用它由包含ImageView的一个RelativeLayout的自定义适配器的GridView。我已经启用了GridView的MultiChoiceMode并启用CAB(语境操作栏)。这个伟大的工程,但我难倒,因为他们选择了我将如何显示在我的网格项目的持久选择。我选择工作在最初的preSS,但我还没有找到一种方法,它会持续,直到该项目处于未选中状态。

I have a GridView using a custom adapter which consists of a relativelayout containing an imageview. I have enabled MultiChoiceMode on the gridview and enabled CAB (Contextual Action Bar). This works great, however I am stumped on how I will show a persistent selector around my grid items as they are selected. My selector works on the initial press, but I have yet to find a way in which it will persist until the item is unselected.

后市展望:用户长presses一个项目,该项目被选择并且该应用程序进入CAB模式。由于每个产品pressed紫色的框架(在XML我的选择语句定义)将出现围绕每个对象,直到它们选中。

Expectation: User long presses an item, the item is selected and the application enters CAB mode. As each item is pressed a purple frame (as defined by my selector statement in the XML) will appear around each object until they are unselected.

结果:用户长presses一个项目,该项目被简略地表示选择器,它消失了,用户得到没有视觉反馈,选择或取消选择的项目,即使它在code的注册。

Result: User long presses an item, the item is briefly showing the selector, it disappears, and user gets no visual feedback to selecting or unselecting items, even though it's registered in code.

我曾尝试每一个选择的事件,但没有似乎处理这个问题。任何变通办法?什么我失踪?

I have tried every single selector event but none seems to handle this. Any workarounds? Anything I'm missing?

什么,我想实现的一个例子是试图通过长preSS在Android 4.0或4.1 Gallery应用程序

An example of what I am trying to achieve is presented by trying to long press an item in the Android 4.0 or 4.1 Gallery application

- > API 15℃; ---

推荐答案

尝试修改布局列表项有不同的背景属性:

Try modifying the layout for your list items to have a different background attribute:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listItemRelativeLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent"
    android:background="?android:attr/activatedBackgroundIndicator">

    ...

</RelativeLayout>

这是Android的属性引用,当你调用listView.setItemChecked(INT指数,布尔检查)这就是使用的选择,以及由于某种原因,它似乎以这种方式工作。

That Android attribute references a selector that's used when you call listView.setItemChecked(int index, boolean checked), and for some reason it seems to work this way.

此外,验证你调用这个列表视图:

Also, verify that you call this on the list view:

listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);