Here is my custom list adapter class where I populate the list items which contain one checkbox and an imageview. On check of the checkbox, an imageview appears on the same row of listview and on click of that imageview, a camera loads. However every first time I load the camera and capture a picture or press back without capturing images, all the checks from the checkboxes disappear, but after the first time everything works normally. Can anyone tell me why this is happening
public class CustomListAdapter extends ArrayAdapter {
private final Activity context;
private final String[] itemname;
private static final int CAMERA_REQUEST = 1888;
public CustomListAdapter(Activity context, String[] itemname) {
super(context, R.layout.merch_items, itemname);
// TODO Auto-generated constructor stub
this.context=context;
this.itemname=itemname;
}
public View getView(final int position,View view, ViewGroup parent){
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.merch_items,null,true);
final ImageView imageView = (ImageView) rowView.findViewById(R.id.merchimageView);
final TextView merchText = (TextView) rowView.findViewById(R.id.merchimagetext);
final CheckBox checkBox = (CheckBox) rowView.findViewById(R.id.checkBox);
imageView.setTag("empty");
checkBox.setText(itemname[position]);
checkBox.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(checkBox.isChecked()){
imageView.setImageResource(R.drawable.camera);
imageView.setTag("available");
}
else{
imageView.setImageDrawable(null);
imageView.setTag("empty");
}
}
});
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(imageView.getTag().toString().equals("available")) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
((Activity)context).startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
}
});
return rowView;
}
}
Aucun commentaire:
Enregistrer un commentaire