我有一个ListView的项目,当你点击它们将改变它的背景颜色(并将在重新启动应用程序后保持背景颜色)。这表示该项已被读取(展开的视图在VieWPager中打开)。我的问题是,因为我已经能够更改ListView项目的背景颜色(对于那些已被点击的项目),当我长按以调出上下文菜单时,在选择项目时,该项目的背景颜色否比往常更长的灰色。结果,我无法“看到”我在上下文模式中选择的内容。我真的不知道如何解决这个问题。有人可以建议吗?
我用来更改ListView中背景项颜色的代码:
public void onListItemClick(ListView l, View v, int postion, long id) {
Article a = ((toReadListAdapter) getListAdapter()).getItem(postion);
// Clicked on items are flagged.
a.setRead(true);
saveToReadList(toReadList);
..........
自定义适配器:
// Defining custom adapter
private class toReadListAdapter extends ArrayAdapter<Article> {
public toReadListAdapter(ArrayList<Article> listToRead) {
super(getActivity(), 0, listToRead);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = getActivity().getLayoutInflater().inflate(R.layout.new_articlelistfragment, null);
}
Article en = getItem(position);
.....
//if the article has been clicked on, then read value is true. Background is set to green.
if(en.isRead()){
convertView.setBackgroundColor(Color.parseColor("#C8E6C9"));
}else{
convertView.setBackgroundColor((Color.parseColor("#ffffff")));
}
return convertView;