Answers for "recyclerview adapter in android"

7

androidx recyclerview dependency

dependencies {
    implementation "androidx.recyclerview:recyclerview:1.1.0"
    // For control over item selection of both touch and mouse driven selection
    implementation "androidx.recyclerview:recyclerview-selection:1.1.0-rc01"
}
Posted by: Guest on May-21-2020
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
1

recyclerview adapter in kotlin

class CustomAdapter(private val dataSet: Array<String>) :
        RecyclerView.Adapter<CustomAdapter.ViewHolder>() {

    class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        
    }

    override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
      
    }


    override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {

      
    }

    override fun getItemCount() {
    }

}
Posted by: Guest on May-31-2021
0

how to set adapter in recyclerview in android

mAppAdapter = new AppAdapter(mModel); // or whatever constructor you want
recyclerView.setAdapter(mAppAdapter);
Posted by: Guest on June-19-2021

Code answers related to "recyclerview adapter in android"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language