0

I want select optionally one image like radio button and put tick mark on that image. How can i do it.Here I add my adapter class and xml file

This is my adapter class.

public class StarCountAdapter extends RecyclerView.Adapter<StarCountAdapter.StarCountHolder> {
    Context context;
    LayoutInflater inflater;
    List<StarCount> starCounts = new ArrayList<>();

    public StarCountAdapter(Context context, List<StarCount> starCounts) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.starCounts = starCounts;
    }
    @Override
    public StarCountHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.star_count_row,parent,false);
        return new StarCountHolder(view);
    }
    @Override
    public void onBindViewHolder(StarCountHolder holder, int position) {
        StarCount model = starCounts.get(position);
        Picasso.with(context)
                .load("http://"+model.getImagePath())
                .into(holder.starImage);
        holder.actorName.setText(model.getName());
        holder.counts.setText(""+model.getCount());
    }
    @Override
    public int getItemCount() {
        return starCounts.size();
    }    
    public class StarCountHolder extends RecyclerView.ViewHolder {
        ImageView starImage;
        TextView actorName,counts;
        public StarCountHolder(View itemView) {
            super(itemView);
            starImage = (ImageView) itemView.findViewById(R.id.starCountIv);
            actorName = (TextView) itemView.findViewById(R.id.acterName);
            counts = (TextView) itemView.findViewById(R.id.counts);
        }
    }
}

This is my star_count_row.xml file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp">
    <ImageView
        android:id="@+id/starCountIv"
        android:layout_width="match_parent"
        android:layout_height="175dp" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="120dp"
        android:orientation="vertical">
        <TextView
            android:id="@+id/acterName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="#000" />
        <TextView
            android:id="@+id/counts"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="#000" />
    </LinearLayout>
</RelativeLayout>

Thank You.

Balaji
  • 33
  • 7
  • keep the picasso image and an extra image of white tickmark with transparent background under a relative layout.Keep it invisible and make it visible on click of the image in your adapter class.Also maintain a boolean value in your model to keep check if the image has been selected or not. – Nidhi Sep 01 '16 at 09:51
  • Sorry I am new for android cant get clearly. Can you explain via code. – Balaji Sep 01 '16 at 10:37
  • For that you have to post your xml and Model class code too. Only then I will be able to help. – Nidhi Sep 01 '16 at 10:44

1 Answers1

0

create custom radio button followin link here you will get your answer

Adding custom radio buttons in android

Community
  • 1
  • 1
Dinesh Saini
  • 335
  • 1
  • 12