选择在ListView中的多个项目 [英] Selecting multiple items in ListView

查看:155
本文介绍了选择在ListView中的多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在ListView中的机器人选择多个项目。

How to select multiple item in ListView in android.

推荐答案

其实你可以;?)这是用户体验的只是一个问题,对

Actually you can ;) It's just a matter of user experience, right?

试试这个,(1)列表控件集

Try this, (1) for list control set

listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);   
listView.setItemsCanFocus(false);

(2)定义列表项为

(2) define list item as

<CheckedTextView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:gravity="center_vertical"
    android:paddingLeft="6dip"
    android:paddingRight="6dip"
    android:checkMark="?android:attr/listChoiceIndicatorMultiple"
    android:background="@drawable/txt_view_bg" />

这是一样的 android.R.layout.simple_list_item_multiple_choice 安卓背景=@可绘制/ txt_view_bg

(3),然后定义绘制txt_view_bg.xml为

(3) And define drawable txt_view_bg.xml as

<item android:drawable="@drawable/selected"
  android:state_checked="true" />  
<item android:drawable="@drawable/not_selected" />

注: - preferred的方式来处理多个选择是与点击项目点击跟踪选择你的自我,而不是根据其状态列表

Note:- The preferred way to handle multiple choice is to track choices your-self with on click item click, rather than depending on its state in list.

这篇关于选择在ListView中的多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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