【发布时间】:2014-12-26 03:02:25
【问题描述】:
我有三个 ArrayList,即 A、B、C。我将 ArrayList A 和 ArrayList B 合并到 ArrayList C(空)中。我能够显示 A 和 B 中的所有元素。我的问题是我想将 A 中的元素显示为绿色,将 B 中的元素显示为灰色。我的代码是这样的
private class MyListAdapter extends BaseAdapter{
LayoutInflater mInflator;
boolean flag;
boolean flag1;
public MyListAdapter(ArrayList<BluetoothDevice> aList) {
// TODO Auto-generated constructor stub
super();
mInflator = TrackDevices.this.getLayoutInflater(null);
cArrayList = aList;
flag = cArrayList.addAll(aArrayList);
flag1 = cArrayList.addAll(bArrayList);
}
@Override
public View getView(int position, View view, ViewGroup parent) {
ViewHolder holder = new ViewHolder();
// TODO Auto-generated method stub
if(view == null){
view = mInflator.inflate(R.layout.track_frag, null);
holder.deviceTag = (TextView)view.findViewById(R.id.track);
if(flag){
view.setBackgroundColor(Color.GREEN);
}else if(flag1){
view.setBackgroundColor(Color.GRAY);
}
view.setTag(holder);
}else{
holder = (ViewHolder)view.getTag();
}
BluetoothDevice device = cArrayList.get(position);
final String deviceName = device.getAddress();
if (deviceName != null && deviceName.length() > 0){
holder.deviceTag.setText(deviceName);
}else{
holder.deviceTag.setText("No devices");
}
return view;
}
}
对于 C 数组列表中的 A 和 B 元素,上述代码始终以绿色显示。如何使每个列表不同。
【问题讨论】:
-
为什么要对这个问题投反对票?怎么了
-
BluetoothDevice 是你的 pojo 类
标签: java android android-listview arraylist adapter