在列表视图中显示当前选择 [英] Showing the current selection in a listview

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

问题描述

正如在平板电脑版的 gmail 和 google talk 中看到的那样,我试图在列表视图中显示当前选择.我知道这不是标准做法,必要时应该避免.在我的程序中,列表视图始终在屏幕上,单击的项目在右侧显示一个新片段(类似于 gmail 和 google talk).

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?

这是我的选择器 xml

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> 

推荐答案

Gmail 和类似应用使用的是 activated 状态,具有适当的行布局.见:

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

简而言之,您:

  • 使用带有激活背景的行布局(例如,android.R.layout.simple_list_item_activated_1)
  • 在您的 ListView
  • 上使用 setChoiceMode(ListView.CHOICE_MODE_SINGLE)
  • 检查"应使用 ListView 上的 setItemChecked() 激活的行以启用激活"状态并具有持久突出显示
  • 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

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

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