user3912760
user3912760

Reputation:

Android: Change image of imageview in listview using a parsequery adapter

I have been able to do many things to each specific item in the ListView depending on position. Now, I'm trying to change the image of an ImageView in the ListView but for some reason i can't. Everytime it is clicked, the ImageView that is a few positions below or above it change instead.

I´m using a ParseQueryAdapter.

    public class MyCustomAdapter extends ParseQueryAdapter<ParseObject> {


        public MyCustomAdapter(Context context, String className,
                int itemViewResource) {
            super(context, className, itemViewResource);
        }

        @Override
        public View getItemView(final ParseObject status, View convertView, ViewGroup parent) {
            convertView = View.inflate(getActivity().getApplicationContext(), R.layout.status_list_view_item, null);
            mListViewReferences(convertView, status);
            statusText = (TextView) convertView.findViewById(R.id.statusText);
            statusText.setText(status.getString("Status")); 

            // Set the count number for the like counter depending on the users that liked it
            likeCounter = (TextView) convertView.findViewById(R.id.likeCounter);
            likeCounter.setText("" + status.getInt("likeCount"));

            ................

            return super.getItemView(status, convertView, parent);
        }

        /**
         * Set References
         * @param View view
         * @param ParseObject status
         */
        private void mListViewReferences(final View view, final ParseObject status) {
            statusLike = (ImageButton) view.findViewById(R.id.statusLike);

            /**
             * onClickListeners and actions to perform
             */

            //Like/Unlike current status
            statusLike.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    /**
                    I want to do it in here, i want to change the image of "statusLike" in here depending on the position.
                    */


                }
            });
}

Ive tried many ways and ive also included this inside the current if/else statements i am using gor the likeCount, but it still does not work. The likeCount works and so does the status text and title. Everything works except for the changing of the image inside the current child position.

Upvotes: 1

Views: 469

Answers (1)

user3912760
user3912760

Reputation:

I was doing it the right way, i was just missing one very important step which was to include notifyDataSetChanged() inside the onClickListener.

Upvotes: 1

Related Questions