【问题标题】:How to change the background color of a previously selected listview item如何更改先前选择的列表视图项的背景颜色
【发布时间】:2011-11-17 15:05:23
【问题描述】:

我面临的情况是我有一个 ListView 项目。当我单击其中一个列表视图项目时,将启动一个新活动,其中显示有关该项目的详细信息。现在,当我单击返回按钮时,我会返回 ListView 活动。我需要做的是通过更改其背景颜色来突出显示我之前单击的列表项。我怎样才能做到这一点。

【问题讨论】:

标签: android


【解决方案1】:
ListView lv = (ListView)this.findViewById(android.R.id.list);
lv.setOnItemClickListener(new OnItemClickListener()
{
    public void onItemClick(AdapterView<?> parent, View view, int position, long id)
    {
           //Before starting the new activity change color
           view.setBackgroundResource(android.R.color.darker_gray);
           // Or any other color you placed in value/color.xml file
    }
});

【讨论】:

    猜你喜欢
    • 2015-01-13
    • 1970-01-01
    • 2016-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-24
    • 2021-02-06
    • 1970-01-01
    相关资源
    最近更新 更多