如何使用可选列表与上下文动作条? [英] How do I use a selectable list with a contextual actionbar?

查看:134
本文介绍了如何使用可选列表与上下文动作条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了全新的Andr​​oid设计标准在这里: http://developer.android。 COM /设计/模式/ selection.html 并想知道第一次如何使我的ListView选择(因为长presses现在应该选择项目,没有表现出像以前那样上下文菜单),然后找出如何将这些信息传递给动作条,以便根据什么选择(多少选择项目时)我可以做一个上下文动作条。我已经签出几个网站,包括 http://www.vogella.de/articles/ AndroidListView / article.html ,但它并没有说明如何做到这一点对ICS的动作条。

I was reading the new Android Design Standards here: http://developer.android.com/design/patterns/selection.html and was wondering first how to make my ListView selectable (because long presses are now supposed to select items, not show a context menu like before), then to figure out how to pass that information to the ActionBar so I can make a contextual ActionBar based on what is selected (and how many items are selected). I've checked out several sites, including http://www.vogella.de/articles/AndroidListView/article.html but it doesn't show how to do it for ICS with the ActionBar.

我不给任何code道歉,但我还没有与列表视图除了使自定义的做任何事情。

I apologize for not giving any code, but I haven't had to do anything with listviews aside from making custom ones.

推荐答案

在第一部分(选择列表项),你需要做两件事情:

For the first part (select list item), you need to do a couple things:

-Depending上下文,设置的ListView为单个或多个选择(取决于您的应用程序),使用setChoiceMode方法。

-Depending on the context, set your ListView to either single or multiple choice (depending on your app), using the setChoiceMode method.

lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
// or
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

- 为了作为选择标记的项目,只是听久preSS并调用ListView的setItemChecked方法。

-in order to mark the item as selected, just listen for a long press and call the ListView's setItemChecked method.

lv.setItemChecked(position, true);

最后,为了使ListView项显示为选中状态,您需要将以下属性添加到该ListView项自定义XML布局:
安卓背景=机器人:ATTR / activatedBackgroundIndicator

Finally, in order for the listview item to show as selected, you need to add the following attribute to the custom XML layout for that listview item:
android:background="?android:attr/activatedBackgroundIndicator"

有关创建上下文动作条,这个过程稍微详细一点,但它在的使用上下文操作模式部分。

For creating contextual Action Bar, the process is a little more detailed, but it's outlined in the Android Developer guide in the Using Contextual Action Mode section.

这篇关于如何使用可选列表与上下文动作条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆