【发布时间】:2012-09-25 04:12:57
【问题描述】:
我想在列表视图中设置特定项目的背景颜色。
我的列表视图是由 ArrayAdapter 使用 ArrayList 生成的。
我计划更改列表视图中的特定项目的背景颜色。
我知道项目在列表中的位置。
这是我生成列表视图的代码。
respondMessageListView = (ListView) findViewById(R.id.respondMessageListView);
respondMessageListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, autoRespondMessages.getMessages()));
谢谢!
[编辑]
根据this post,如果在onCreate()中使用setSelection无效,解决方法是“删除PullToRefreshListView中的onAttachedToWindow方法”。我不太了解解决方案。请问我应该如何做到这一点?我是Activity 的子类,所以我不能再继承任何其他类了。
【问题讨论】:
-
我试过了,它在 myList.getSelectedView().setBackgroundColor(getResources().getColor(Color.RED)) 上给了我 nullpointerexception;