ImageView as CheckBox in ListView

Screenshot_2014-11-30-02-02-51
Favorite or not? Selected, not selected? As Android developer I faced this issue many times. This code snippet shows how to demonstrate imageview as checkbox. You just use custom list adapter which extends BaseAdapter:

public class TopDrugstoresAdapter extends BaseAdapter {
.....

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

.....

            if (drugstore.getFavorite()) {
                ivStar.setImageResource(R.drawable.ic_active_star);
            }
            ivStar.setTag(drugstore);

            ivStar.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Drugstore drugstore = (Drugstore) ivStar.getTag();

                    if (drugstore.getFavorite()) {
                        drugstore.setFavorite(false);
                        ivStar.setImageResource(R.drawable.ic_inactive_star);
                    } else {
                        drugstore.setFavorite(true);
                        ivStar.setImageResource(R.drawable.ic_active_star);
                    }
                }
            });

.....

    }

}