如何突出选中的列表项中的android? [英] How to highlight selected list item in android?

查看:222
本文介绍了如何突出选中的列表项中的android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用我有列表视图和细节视图列表的每个项目。对于平板电脑我已经展示的项目列表视图和所选项目的详细信息视图如下:

所以,我的问题是我怎么能突出所选项目用户点击列表项目后。

我使用一个BaseAdapter加载列表我view.How可以做到这一点任何想法?

编辑:

是为chintan khetiya提到我用下面的XML文件的列表项的背景,但它不会欣喜的是,选择的项目。什么我错过了?

 < XML版本=1.0编码=UTF-8&GT?;
<选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
<项目
 机器人:state_selected =假
    机器人:STATE_ pressed =假
    机器人:可绘制=@色/ abs__background_holo_light/>
<项目的android:STATE_ pressed =真
    机器人:可绘制=@色/ action_bar_blue/>
<项目安卓state_selected =真
 机器人:STATE_ pressed =假
    机器人:可绘制=@色/ action_bar_blue/>
< /选择器>
 

解决方案

您的查询:

  

我的问题是我怎么能突出所选项目用户点击列表项目后。

我想你问的选择。意思是,如果该列表行的焦点状态,那么就应该看不同形式的所有其他行。当你preSS或触摸行同样的事情。

有关,你必须做出 Selector.xml 文件中可绘制文件夹,只是把那在列表行选择文件

该文件应该有不同的标记像焦点单击 - preSS 并更改绘制对象按状态。

更新:

只需更换你的图标,并保存在可绘制文件夹。

 < XML版本=1.0编码=UTF-8&GT?;
<选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

    <  - !pressed  - >
    <项目机器人:可绘制=@可绘制/ p_paly_ preSS安卓STATE_ pressed =真/>

    <! - 选择 - >
    <项目机器人:可绘制=@可绘制/ p_play机器人:state_selected =真/>

    <! - 集中 - >
    <项目机器人:可绘制=@可绘制/ p_paly_ preSS机器人:state_focused =真/>

    <! - 默认 - >
    <项目机器人:可绘制=@可绘制/ p_play/>

< /选择器>
 

In my android application i have list view and detail view for each list item. For tablets i have shown list view of items and selected item's detail view as follows.

So my problem is how can i highlight the selected item after user clicks on list item.

I am using a BaseAdapter to load list view.How can i do this any idea??

EDIT:

Yes as chintan khetiya mentioned i have used following xml file as the background of list item but it will not delighted the selected item. What have i missed?

    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item 
 android:state_selected="false"
    android:state_pressed="false" 
    android:drawable="@color/abs__background_holo_light" />
<item android:state_pressed="true" 
    android:drawable="@color/action_bar_blue" />
<item android:state_selected="true"
 android:state_pressed="false" 
    android:drawable="@color/action_bar_blue" />
</selector>

解决方案

Your Query :

my problem is how can i highlight the selected item after user clicks on list item.

I think you are asking about selector. Mean if the list row in focus state then it should be look different form all other row. Same thing when you press or Touch the Row.

For that you have to make Selector.xml File in Drawable folder and just put that selector file in your list row

That file should have different tag like Focus-Click-Press and change the Drawable as per state.

Update :

Just Replace Your icon and save in Drawable folder.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Pressed -->
    <item android:drawable="@drawable/p_paly_press" android:state_pressed="true"/>

    <!-- selected -->
    <item android:drawable="@drawable/p_play" android:state_selected="true"/>

    <!-- focused -->
    <item android:drawable="@drawable/p_paly_press" android:state_focused="true"/>

    <!-- default -->
    <item android:drawable="@drawable/p_play"/>

</selector>

这篇关于如何突出选中的列表项中的android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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