Nenco Nenco - 2 months ago 15
Android Question

How to check which image listview contains?

I'm making a simple app with a custom listview and a database and I got stuck with checking which image a listview contains.

Example of what I wanna do:

If I want to update job1 then I click on job1 and it should open the dialog with the "under construction" selected.

job2 with done selected etc..

I wanna know how to make a check if list item contains "R.drawable.job_done"?

I know that this is not actual code but this is what I wanna do:

if(listviewItem.contains R.drawable.job_done){

radioButtonJobDoneFromUpdateDialog.setChecked(true);



}else if (listviewItem.contains R.drawable.job_under_construction){

radioButtonJobUnderconstructionFromUpdateDialog.setChecked(true);



}else if (listviewItem.contains R.drawable.job_incoming){


radioButtonJobIncomingFromUpdateDialog.setChecked(true);



}


Give me a simple example guys, tnx in advance.

SOLVED!!!

I made a hidden textview and I saved the names of icons as strings and now I'm making checks with those strings. Anyway, tnx for trying to help guys.

Custom listview adapter:

public class Business_custom_listView_adapter extends ArrayAdapter<BusinessObjects> {


Context context;
DatabaseHandler handler;
int layoutResourceId;
ArrayList<BusinessObjects> data = new ArrayList<BusinessObjects>();

public Business_custom_listView_adapter(Context context, int layoutResourceId, ArrayList<BusinessObjects> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ImageHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ImageHolder();
holder.txtTitle = (TextView) row.findViewById(R.id.tvJobListItemID);
holder.imgIcon = (ImageView) row.findViewById(R.id.ivJobStatusID);
row.setTag(holder);
} else {
holder = (ImageHolder) row.getTag();
}
BusinessObjects picture = data.get(position);
holder.txtTitle.setText(picture.getNameOfTheJob());
byte[] outImage = picture.getImage();
ByteArrayInputStream imageStream = new ByteArrayInputStream(outImage);
Bitmap theImage = BitmapFactory.decodeStream(imageStream);
holder.imgIcon.setImageBitmap(theImage);
return row;
}


static class ImageHolder {
ImageView imgIcon;
TextView txtTitle;
}
}


Design of the app:

job status

listview with jobs

Answer

Try it this way

  if (listviewItem.imgIcon.getDrawable() == getResources().getDrawable(R.drawable.job_done)) {
                //do work here
     } else if (listviewItem.imgIcon.getDrawable() == getResources().getDrawable(R.drawable.job_under_construction)) {
   //do work here
     } else if (listviewItem.imgIcon.getDrawable() == getResources().getDrawable(R.drawable.job_incoming)) {
     //do work here
     }
Comments