Answers for "recycler adapter android example"

1

recycler adapter class android java

//java,recycler adapter class,Android studio,2021/09/23
//this is example only. copy,paste,change and use it 

public class RecyclerAdapterClass extends RecyclerView.Adapter<RecyclerAdapterClass.MyViewHolder> {
    List<String> headlineList=new ArrayList<>();
    List<String> descriptionList=new ArrayList<>();

    Context context;
    int myPosition;
    URL url;

    public RecyclerAdapterClass(Context context, List<String> headlineList, List<String> descriptionList) {
        this.context=context;
        this.headlineList=headlineList;
        this.descriptionList=descriptionList;
   
    }
    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater inflater=LayoutInflater.from(context);
        View view=inflater.inflate(R.layout.single_item,parent,false);

        return new MyViewHolder(view);
    }
    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {

   
        holder.rowHeadline.setText(headlineList.get(position));
        holder.rowDescription.setText(descriptionList.get(position))

        holder.singleRowLayout.setOnClickListener(v -> { 		//Click event 

            //Do what you want...
        });
    }
    @Override
    public int getItemCount() {
        return headlineList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        TextView rowHeadline,rowDescription;
        Linearlayout singleRowLayout;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
          
            rowHeadline=itemView.findViewById(R.id.rowHeadline);
            rowDescription=itemView.findViewById(R.id.rowDescription);
          
            singleRowLayout=itemView.findViewById(R.id.singleItemLayout);

        }
    }
        @SuppressLint("WrongThread")
        @Override
        protected void onPostExecute(Bitmap bitmap) {
            super.onPostExecute(bitmap);

        }
        @Override
        protected void onProgressUpdate(Void... values) {
            super.onProgressUpdate(values);
        }

    }
}
Posted by: Guest on September-23-2021

Code answers related to "recycler adapter android example"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language