Android app issue in love button 
Tags: android, java
Published: 2020-04-07 04:28:47

I implement a simple app that =can user upload image and retrieved in recycler view other users can see that image and give like to it or share it when the user press on like btn it converts to red heart, but it isn't converted to red heart, below is my code I will be pleased if anyone helps me to solve this problem and thank you.


    ///interface to get position
    @Override
    public void onitemclick(int position) {

        position_of_image=position;
        int num1=uploads.get(position_of_image).getNumber_likes();
        uploads.get(position_of_image).setNumber_likes(num1+1);

       String id=uploads.get(position_of_image).getId();
       int number= uploads.get(position_of_image).getNumber_likes();
       String name= uploads.get(position_of_image).getName();
       String url=uploads.get(position_of_image).getImageUrl();

       //updating the tables

       Map<String,Object> map=new HashMap<>();
       map.put(id,new Upload(name,url,number,id));
        uploads.clear();
        mDatabaseRef.updateChildren(map);
        mRecyclerView.smoothScrollToPosition(position_of_image);

    }

**and this is my adapter**

package com.example.newhistogram;


public class ImageAdapter extends 
RecyclerView.Adapter<ImageAdapter.ImageViewHolder> {
    private Context mContext;
    private List<Upload> mUploads;
    private  onlikeclic  mlistener;

    public ImageAdapter(Context context, List<Upload> uploads) {
        mContext = context;
        mUploads = uploads;

    }

    @Override
    public ImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(mContext).inflate(R.layout.image_item, parent, false);
        return new ImageViewHolder(v);
    }

    @Override
    public void onBindViewHolder(final ImageViewHolder holder, final int position) {
        final Upload uploadCurrent = mUploads.get(position);

        holder.textViewName.setText(uploadCurrent.getName());

        Picasso.with(mContext)
                .load(uploadCurrent.getImageUrl())
                .placeholder(R.mipmap.ic_launcher)
                .fit()
                .centerCrop()
                .into(holder.imageView);

        holder.NO_likes.setText(String.valueOf(uploadCurrent.getNumber_likes()));

    }

    @Override
    public int getItemCount() {
        return mUploads.size();
    }


    public class ImageViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        public TextView textViewName;
        public ImageView imageView;
        public TextView NO_likes;
        private ImageView like;
        private Button share;


        public ImageViewHolder(View itemView) {
            super(itemView);

            textViewName = itemView.findViewById(R.id.text_view_name);
            imageView = itemView.findViewById(R.id.image_view_upload);
            NO_likes = itemView.findViewById(R.id.number_of_likes);

            like = itemView.findViewById(R.id.like);
            like.setOnClickListener(this);

        }

        @Override
        public void onClick(View v) {
        if (mlistener!=null){
            int position=getAdapterPosition();
            if (position!=RecyclerView.NO_POSITION){
                mlistener.onitemclick(position);

            }


        }


        }

    }
    public interface  onlikeclic{
        void onitemclick(int position);


    }
    public void setonitemclicklistener(onlikeclic listener){
        mlistener=listener;
    }

}