ListView项的背景颜色变化 [英] listview item background color change

查看:126
本文介绍了ListView项的背景颜色变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的Andr​​oid应用程序。我已经通过创建一个ListView

I am working on an android application. I have created a listview by using

setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,arrayname));   
getListView().setTextFilterEnabled(true);   

现在我想改变所选项目的颜色。我可以通过将改变所选项目的背景

Now i want to change the selected item's color. I could change the background of the selected item by placing

listviewobject.getChildAt(position).setBackgroundColor(Color.BLACK);

在onListItemClick()

in onListItemClick()

这code为改变背景颜色,但如果我选择的任何其他列表项,然后还了previously点击列表项的颜色是red.So我通过

this code is changing the background color but if I select any other list item then also the previously clicked list item's color is red.So I change the previously clicked listitem's color by

l.getChildAt(prevpos).setBackgroundColor(Color.BLACK);

现在的问题是,如果我改变$ P $的背景pviously点击listItems中的色彩black.Then我看不到我再次点击,然后在那个特定的listitem.I文本只有我能看到该项目的文本。所以它的外观weired.please帮助我的朋友

now the problem is if i change the background of previously clicked listitems color to black.Then i can't see the text on that particular listitem.I i click again then only i can see the text on that item.So its look weired.please help me friends

推荐答案

在经过大量的帖子和博客,我发现这个解决方案,它为我工作...

After going through lots of posts and blogs i found this solution it works for me...

声明行变量全局

public View row;

your_list.setOnItemClickListener(new OnItemClickListener() {

    public void onItemClick(AdapterView<?> a, View v,
                        int position, long id) {

    if (row != null) {
        row.setBackgroundResource(R.color.orange);
    }
    row = v;
    v.setBackgroundResource(R.color.transparent_green);
)};

这篇关于ListView项的背景颜色变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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