亮点列表视图项目的android [英] highlight listview items android
本文介绍了亮点列表视图项目的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自定义的基本适配器列表视图。当我填充列表我要检查对象中的一个布尔值,我填充ListView和如果这是真的改变该行的背景颜色。
公共查看getView(INT位置,查看convertView,父母的ViewGroup){
LoginsList进入= listOfLoginsLists.get(位置);
如果(convertView == NULL){
LayoutInflater吹气=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.lists_row,NULL);
} TextView的LISTNAME =(TextView中)convertView.findViewById(R.id.tvListName);
ListName.setText(entry.getListName()); TextView的ListDescription =(TextView中)convertView.findViewById(R.id.tvListDescription);
ListDescription.setText(entry.getListDescription()); 按钮发送=(按钮)convertView.findViewById(R.id.bSend);
Send.setOnClickListener(本);
Send.setTag(输入); RelativeLayout的RelLayout =(RelativeLayout的)convertView.findViewById(R.id.layoutListsRow);
RelLayout.setFocusableInTouchMode(假);
RelLayout.setFocusable(假);
RelLayout.setOnClickListener(本);
RelLayout.setTag(输入); 如果(entry.isSent()){
RelLayout.setBackgroundColor(Color.parseColor(#4400FF00));
} 返回convertView;
}
但是,这code不工作的权利。当我滚动列表视图中的行颜色搞的一团糟。
解决方案
如果(entry.isSent()){
RelLayout.setBackgroundColor(Color.parseColor(#4400FF00));
}其他{
RelLayout.setBackgroundColor(//默认颜色);
}
I have listview with custom base adapter. When I populate the list I have to check a boolean in the object I'm populating the listview and if it is true to change the background color of that row.
public View getView(int position, View convertView, ViewGroup parent) {
LoginsList entry = listOfLoginsLists.get(position);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.lists_row, null);
}
TextView ListName = (TextView) convertView.findViewById(R.id.tvListName);
ListName.setText(entry.getListName());
TextView ListDescription = (TextView) convertView.findViewById(R.id.tvListDescription);
ListDescription.setText(entry.getListDescription());
Button Send = (Button) convertView.findViewById(R.id.bSend);
Send.setOnClickListener(this);
Send.setTag(entry);
RelativeLayout RelLayout = (RelativeLayout) convertView.findViewById(R.id.layoutListsRow);
RelLayout.setFocusableInTouchMode(false);
RelLayout.setFocusable(false);
RelLayout.setOnClickListener(this);
RelLayout.setTag(entry);
if (entry.isSent()) {
RelLayout.setBackgroundColor(Color.parseColor("#4400FF00"));
}
return convertView;
}
But this code doesn't work right. When I scroll the list view the rows colors get messed up.
解决方案
if (entry.isSent()) {
RelLayout.setBackgroundColor(Color.parseColor("#4400FF00"));
}else {
RelLayout.setBackgroundColor(//default color);
}
这篇关于亮点列表视图项目的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文