显示当前选择在ListView [英] Showing the current selection in a listview

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

问题描述

正如在Gmail中的平板电脑版和谷歌谈我试图显示当前选择的列表视图。我知道这是不是标准的做法和必要。我的计划时,列表视图常是在屏幕上,单击的项目显示了一个新的片段向右(类似Gmail和谷歌谈)应尽​​量避免。

要避免用户在猜测哪些项目已经选定我想显示当前选择,我试图创造一个选择,但它被点击它变回正常的背景后。

我怎样才能做到这一点?

这是我的选择XML

 <选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
<项目机器人:可绘制=@可绘制/ list_item_bg2机器人:STATE_ pressed =假的Andr​​oid版本:state_selected =假
    机器人:state_focused =FALSE/>
<项目机器人:可绘制=@可绘制/ list_item_selected_bg2机器人:STATE_ pressed =真/>
<项目机器人:可绘制=@可绘制/ list_item_selected_bg2机器人:STATE_ pressed =假的Andr​​oid版本:state_focused =假
    机器人:state_selected =真正的机器人:state_checked =FALSE/>
<项目机器人:可绘制=@可绘制/ list_item_selected_bg2机器人:STATE_ pressed =假的Andr​​oid版本:state_focused =真
    机器人:state_selected =FALSE/>
<项目机器人:可绘制=@可绘制/ list_item_selected_bg2机器人:STATE_ pressed =假的Andr​​oid版本:state_focused =假
    机器人:state_selected =假的Andr​​oid版本:state_checked =真/>
<项目机器人:可绘制=@可绘制/ list_item_selected_bg2机器人:STATE_ pressed =真正的机器人:state_focused =真
    机器人:state_selected =真正的机器人:state_checked =真/>
<项目机器人:可绘制=@可绘制/ list_item_selected_bg2机器人:STATE_ pressed =真/>



< /选择器>
 

解决方案

什么Gmail和类似的应用程序使用的是启动状态,用适当的行布局。参见:

  • <一个href="http://stackoverflow.com/questions/5274982/setting-android-background-persistence-menu-bar-using-attribute-on-older-ver">Setting Android的背景和放大器;持久性菜单栏 - 在旧版本使用属性导致崩溃 - 是否有一个主题/模式方法
  • <一个href="http://stackoverflow.com/questions/6588750/change-colour-of-activated-list-item-background-on-honeycomb">Change激活列表项的背景蜂窝
  • 颜色

简而言之,您:

  • 使用一排布置与活化的背景下(例如, android.R.layout.simple_list_item_activated_1
  • 使用 setChoiceMode(ListView.CHOICE_MODE_SINGLE)的ListView
  • 在检查,应该用被激活的行 setItemChecked()的ListView 启用启动状态,并且有持续的亮点

As seen in the tablet version of gmail and google talk I am trying to show the current selection in a listview. I know this is not standard practice and should be avoided when necessary.in my program the listview is alway on the screen and the item clicked shows a new fragment to the right (similar to gmail and google talk).

To avoid the user from guessing what item has been selected I would like to show the current selection, I tried creating a selector but after it is clicked it changes back to the normal background.

how can I achieve this?

this is my selector xml

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/list_item_bg2" android:state_pressed="false" android:state_selected="false"
    android:state_focused="false"/>
<item android:drawable="@drawable/list_item_selected_bg2" android:state_pressed="true"/>
<item android:drawable="@drawable/list_item_selected_bg2" android:state_pressed="false" android:state_focused="false"
    android:state_selected="true" android:state_checked="false"/>
<item android:drawable="@drawable/list_item_selected_bg2" android:state_pressed="false" android:state_focused="true"
    android:state_selected="false"/>
<item android:drawable="@drawable/list_item_selected_bg2" android:state_pressed="false" android:state_focused="false"
    android:state_selected="false" android:state_checked="true"/>
<item android:drawable="@drawable/list_item_selected_bg2" android:state_pressed="true" android:state_focused="true"
    android:state_selected="true" android:state_checked="true"/>
<item android:drawable="@drawable/list_item_selected_bg2" android:state_pressed="true"/>



</selector> 

解决方案

What Gmail and similar apps use is the activated state, with an appropriate row layout. See:

In a nutshell, you:

  • Use a row layout with an activated background (e.g., android.R.layout.simple_list_item_activated_1)
  • Use setChoiceMode(ListView.CHOICE_MODE_SINGLE) on your ListView
  • "Check" the row that should be activated using setItemChecked() on your ListView to enable the "activated" state and have the persistent highlight

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

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