0

I have to change image on click of that image. When I am trying to do that it is changing image but not at that position.

Code

   public class InteractiveArrayAdapter extends
        ArrayAdapter<HashMap<String, String>> {
    public boolean[] checkBoxState;
    boolean[] favStar;
    ViewHolder viewholder;
    // private Object inflater;
    private LayoutInflater inflater;
    private ArrayList<HashMap<String, String>> menuItems;

    public InteractiveArrayAdapter(Context context, int resource,
            ArrayList<HashMap<String, String>> menuItems) {
        super(context, resource, menuItems);
        this.menuItems = menuItems;
        inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        checkBoxState = new boolean[menuItems.size()];
    }

    private class ViewHolder {
        // ImageView photo;
        TextView title, link, published, description;
        // ImageButton newsCheck;
        public ImageView newsCheck;
    }

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

        if (convertView == null) {
            // inflater =
            // LayoutInflater.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.list_item1, null);
            viewholder = new ViewHolder();

            // cache the views
            // viewholder.photo=(ImageView)
            // convertView.findViewById(R.id.photo);
            viewholder.title = (TextView) convertView
                    .findViewById(R.id.news_title);
            // viewholder.link = (TextView) convertView.findViewById(R.id.link);
            viewholder.published = (TextView) convertView
                    .findViewById(R.id.published);
            viewholder.description = (TextView) convertView
                    .findViewById(R.id.description);
            viewholder.newsCheck = (ImageView) convertView
                    .findViewById(R.id.newsCheck);
            System.out.println("position" + position);

            // link the cached views to the convertview
            convertView.setTag(viewholder);

        } else
            viewholder = (ViewHolder) convertView.getTag();

        HashMap<String, String> catalog_list = new HashMap<String, String>();
        catalog_list = menuItems.get(position);

        // viewholder.link.setText(catalog_list.get("NEWS_KEY_LINK")
        //
        // viewholder.link.setText(catalog_list
        // .get(NewsXMLParsingActivity.NEWS_KEY_LINK));
        viewholder.title.setText(catalog_list
                .get(NewsXMLParsingActivity.NEWS_KEY_TITLE));
        viewholder.published.setText(catalog_list
                .get(NewsXMLParsingActivity.NEWS_KEY_PUB));
        viewholder.description.setText(catalog_list
                .get(NewsXMLParsingActivity.NEWS_KEY_DESCRIPTION));
        viewholder.newsCheck.setTag(position);
        viewholder.newsCheck.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                viewholder.newsCheck.getTag(position);
                System.out.println(v.getTag() + "qqqqqq");
                int position = (Integer) v.getTag(); // This will retrieve your
                                                        // clicked image

                viewholder.newsCheck.setImageResource(R.drawable.favv2);

            }
        });

        return convertView;

    }
}
AndyFaizan
  • 1,833
  • 21
  • 30
poojagupta
  • 982
  • 2
  • 12
  • 26
  • If you are implementing like, check / uncheck concept, using ImageViews, have a look at my answer here: http://stackoverflow.com/a/16569700/1739882... Hope it helps you !!! – Chintan Soni Mar 08 '14 at 09:06
  • @shree202 for imageview getChecked function is not working.what should I do then – poojagupta Mar 08 '14 at 09:14
  • In my case, I am using ArrayAdapter of type `Category` which is the class I created for holding data, while you are using `HashMap` can you try implementing the way I am going ? – Chintan Soni Mar 08 '14 at 09:23

0 Answers0