我目前有一个ListView
Adaptor
.
如何ListView
根据ListView
项目更改背景颜色?
i.e if(item.param1 == "some")
{
colour1
}
else
{
colour2
}
我的代码
import java.util.HashMap;
import java.util.List;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
import android.widget.TextView;
public class SpecialAdapter extends SimpleAdapter {
private int[] colors = new int[] { 0xFFFFFFFF, 0xFF000000 };
TextView tv1, tv2;
public SpecialAdapter(Context context, List<HashMap<String, String>> items, int resource, String[] from, int[] to) {
super(context, items, resource, from, to);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
view.setBackgroundColor(colors[colorPos]);
return view;
}
}
希望这是有道理的