iNoobAvicena

RSAdapter Android

Dec 5th, 2021
630
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class RSAdapter extends RecyclerView.Adapter<RSAdapter.MyViewHolder> {
  2.  
  3.     String data[];
  4.     Context context;
  5.  
  6.     public RSAdapter(Context ct, String cate[]) {
  7.         context = ct;
  8.         data = cate;
  9.     }
  10.  
  11.     @NonNull
  12.     @Override
  13.     public RSAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  14.         LayoutInflater inflater = LayoutInflater.from(context);
  15.         View view = inflater.inflate(R.layout.category_column, parent, false);
  16.         return new RSAdapter.MyViewHolder(view);
  17.     }
  18.     @Override
  19.     public void onBindViewHolder(RSAdapter.MyViewHolder holder, int position) {
  20.         holder.cat.setText(data[position]);
  21.     }
  22.     @Override
  23.     public int getItemCount() {
  24.         return data.length;
  25.     }
  26.  
  27.     public class MyViewHolder extends RecyclerView.ViewHolder {
  28.         TextView cat;
  29.         public MyViewHolder(@NonNull View itemView) {
  30.             super(itemView);
  31.             cat = itemView.findViewById(R.id.category);
  32.         }
  33.     }
  34. }
RAW Paste Data