简体   繁体   中英

android dynamic images put tick mark and select optionally one image

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.

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

Adding custom radio buttons in android

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM