This is my class
public class AdapterContact extends BaseAdapter {
private Context context;
private ArrayList<Datamodel> arrModel;
public ArrayList<Datamodel> arrSelectedModel;
// private ArrayList<Boolean> arrCheckboxState;
ViewHolder holder;
ImageLoader imageloader;
public AdapterContact(Context context, ArrayList<Datamodel> arrModel) {
this.context = context;
this.arrModel = arrModel;
arrSelectedModel = new ArrayList<Datamodel>();
imageloader = new ImageLoader(context);
}
@Override
public int getCount() {
return arrModel.size();
}
@Override
public Object getItem(int position) {
return arrModel.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.row_contact, null);
holder.checkBox = (CheckBox) convertView
.findViewById(R.id.rowcontact_checkbox);
holder.txtContactName = (TextView) convertView
.findViewById(R.id.rowcontact_txtName);
holder.imgProfilepic = (ImageView) convertView
.findViewById(R.id.rowcontact_imgProfile);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtContactName.setText(arrModel.get(position).contactName);
holder.checkBox
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
int position = (Integer) buttonView.getTag();
if (isChecked) {
// arrCheckboxState.set(position, true);
arrModel.get(position).setChecked(true);
arrSelectedModel.add(arrModel.get(position));
} else {
arrModel.get(position).setChecked(false);
// arrCheckboxState.set(position, false);
arrSelectedModel.remove(arrModel.get(position));
}
}
});
holder.checkBox.setTag(position);
holder.checkBox.setChecked(arrModel.get(position).isChecked);
if (arrModel.get(position).isActive) {
holder.checkBox.setVisibility(View.GONE);
}
AQuery aq = new AQuery(context);
aq.id(holder.imgProfilepic).image(arrModel.get(position).picturePath,
false, false, 0, R.drawable.imge);
String url2 = arrModel.get(position).picturePath + "?t="
+ System.currentTimeMillis();
aq.id(holder.imgProfilepic).image(url2, false, false, 0,
R.drawable.imge);
convertView.setBackgroundColor(Color.parseColor("#ffffff"));
return convertView;
}
class ViewHolder {
TextView txtContactName;
ImageView imgProfilepic;
CheckBox checkBox;
}
}
this is my XMl :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dip"
android:background="#ffffff"
android:orientation="vertical" >
<com.lociiapp.utils.RoundedImageView
android:id="@+id/rowcontact_imgProfile"
android:layout_width="46dip"
android:layout_height="46dip"
android:layout_centerVertical="true"
android:layout_marginBottom="7dip"
android:layout_marginLeft="7dip"
android:layout_marginTop="7dip" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="70dip"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/rowcontact_imgIcon"
android:layout_toRightOf="@+id/rowcontact_imgProfile"
android:orientation="vertical" >
<TextView
android:id="@+id/rowcontact_txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginTop="17dip"
android:text="Usama Sadiq"
android:textColor="#3c3b3b"
android:textSize="17dip" />
</RelativeLayout>
<CheckBox
android:id="@+id/rowcontact_checkbox"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:button="@drawable/ic_launcher" />
</RelativeLayout>
i am printing data in listview with checkbox selection when item not checked or dfault then checkbox background image will x and if we checked or enable check box of any item then background image should change i am tied to set dfault image in xml and after checked background is not changing please check code where am doing wrong . rowcontact_checkbox id of check box please suggest me