setBackgroundColor(ListView) 依赖于数据
setBackgroundColor (ListView) depend on the data
我将创建一个动态 ListView
来显示来自 json 服务器的数据。我想让 setBakgroundColor
依赖于数据中的某个对象。
例如:
json 是
{"Order":[{"id":1,
"situation":"notchecked",
"status":"Processing"},
{"id":2,
"situation":"checked",
"status":"Processing"}]}
如果情况 == 未检查
convertView.setBackgroundColor(Color.GREEN);
这是我在 BaseAdapter 中的视图
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
convertView = inflater.inflate(R.layout.complete_order_row, parent,
false);
if ()......{
convertView.setBackgroundColor(Color.GREEN);
}
}
TextView situation = (TextView) convertView
.findViewById(R.id.situation);
situation.setText(catList.get(position).getSituation());
TextView status= (TextView) convertView
.findViewById(R.id.status);
status.setText(catList.get(position).getStatus());
TextView id= (TextView) convertView
.findViewById(R.id.id);
id.setText(catList.get(position).getId));
return convertView;
}
你几乎做对了,但每次都需要设置它,无论是在回收还是不回收 convertView 时:
if (convertView == null) {
convertView = inflater.inflate(R.layout.complete_order_row, parent,
false);
//...
}
TextView situation = (TextView) convertView
.findViewById(R.id.situation);
situation.setText(catList.get(position).getSituation());
if (catList.get(position).getSituation().equals("notchecked")) {
convertView.setBackgroundColor(Color.GREEN);
} else {
convertView.setBackgroundColor(Color.BLUE);
}
我将创建一个动态 ListView
来显示来自 json 服务器的数据。我想让 setBakgroundColor
依赖于数据中的某个对象。
例如:
json 是
{"Order":[{"id":1,
"situation":"notchecked",
"status":"Processing"},
{"id":2,
"situation":"checked",
"status":"Processing"}]}
如果情况 == 未检查
convertView.setBackgroundColor(Color.GREEN);
这是我在 BaseAdapter 中的视图
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
convertView = inflater.inflate(R.layout.complete_order_row, parent,
false);
if ()......{
convertView.setBackgroundColor(Color.GREEN);
}
}
TextView situation = (TextView) convertView
.findViewById(R.id.situation);
situation.setText(catList.get(position).getSituation());
TextView status= (TextView) convertView
.findViewById(R.id.status);
status.setText(catList.get(position).getStatus());
TextView id= (TextView) convertView
.findViewById(R.id.id);
id.setText(catList.get(position).getId));
return convertView;
}
你几乎做对了,但每次都需要设置它,无论是在回收还是不回收 convertView 时:
if (convertView == null) {
convertView = inflater.inflate(R.layout.complete_order_row, parent,
false);
//...
}
TextView situation = (TextView) convertView
.findViewById(R.id.situation);
situation.setText(catList.get(position).getSituation());
if (catList.get(position).getSituation().equals("notchecked")) {
convertView.setBackgroundColor(Color.GREEN);
} else {
convertView.setBackgroundColor(Color.BLUE);
}