import android.content.Context;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.RequiresApi;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;

public class Adapter extends RecyclerView.Adapter<Adapter.MyViewHolder> {

    private ArrayList<String> arraylist;
    Context context;
    private MyInterface myInterface;

    public Adapter(Context context, ArrayList<String> arraylist) {
        this.context = context;
        this.arraylist = arraylist;

    public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        public TextView tvView;

        public MyViewHolder(View view) {
            tvView = view.findViewById(;

        public void onClick(View view) {
            if (myInterface != null) myInterface.onItemClick(view, getAdapterPosition());

    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.row, parent, false);
        return new MyViewHolder(itemView);

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public void onBindViewHolder(final MyViewHolder holder, int position) {
//        holder.tvView.

    public int getItemCount() {
        return arraylist.size();

    public void setClickListener(MyInterface itemClickListener) {
        this.myInterface = itemClickListener;

    public interface MyInterface {
        void onItemClick(View view, int position);

downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter