3 개의 ArrayList, 즉 A, B, C가 있습니다. ArrayList A와 ArrayList B를 ArrayList C (비어 있음)에 병합했습니다. 나는 A와 B 모두의 모든 요소를 표시 할 수 있습니다. 제 문제는 A에서 녹색으로, B에서 요소를 greay 색상으로 표시하려고합니다. 내 코드는 다음과 같습니다.android의 saparate 목록에 2 가지 색상이 있습니다.
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 arraylist의 A 및 B 요소에 대해 항상 녹색으로 표시됩니다. 각 목록마다 다른 방법.
왜이 질문에 대한 반대 투표? 무엇이 잘못 되었습니까 – Shiv
BluetoothDevice가 귀하의 pojo 클래스입니다 – Lokesh