我想在没有onitemclick()方法的情况下更改列表视图项背景颜色。因为首先我要检查项目数据,并根据它改变颜色。我该怎么办?
答案 0 :(得分:0)
<击> 撞击>
<击>listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position,
long id) {
if(items.get(position).getSomething().equals(Something){
// If your condition fulfills then change background color
listView.getChildAt(position).setBackgroundColor(#55667788);
}
}
});
击> <击> 撞击>
修改强>
@Override
public View getView(final int position, View convertView, ViewGroup arg2) {
// TODO Auto-generated method stub
if (convertView == null) {
LayoutInflater inflater = context.getLayoutInflater();
convertView = inflater.inflate(R.layout.row_counter, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.name = (TextView) convertView.findViewById(R.id.tv_name);
viewHolder.number = (TextView) convertView
.findViewById(R.id.tv_number);
viewHolder.row = (TextView) convertView
.findViewById(R.id.rel_row);
convertView.setTag(viewHolder);
}
holder = (ViewHolder) convertView.getTag();
currentModel = list.get(position);
holder.name.setText(currentModel.getName());
holder.number.setText(currentModel.getNumber());
if(holder.name.equals("SOMETHING")){
holder.row.setBackgroundColor("#55667788");
}else{
holder.row.setBackgroundColor("#000000");
}
return convertView;
}