Nenco Nenco - 1 year ago 127
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){


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


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



Give me a simple example guys, tnx in advance.


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; = data;

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(;
holder.imgIcon = (ImageView) row.findViewById(;
} else {
holder = (ImageHolder) row.getTag();
BusinessObjects picture = data.get(position);
byte[] outImage = picture.getImage();
ByteArrayInputStream imageStream = new ByteArrayInputStream(outImage);
Bitmap theImage = BitmapFactory.decodeStream(imageStream);
return row;

static class ImageHolder {
ImageView imgIcon;
TextView txtTitle;

Design of the app:

job status

listview with jobs

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download