Answers for "android recyclerview adapter"

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
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
0

remove item from adapter android recyclerview

private void removeItem(int position) {
    int newPosition = holder.getAdapterPosition();
    model.remove(newPosition);
    notifyItemRemoved(newPosition);
    notifyItemRangeChanged(newPosition, model.size());
}
Posted by: Guest on June-08-2020
0

add textview to recyclerview

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ScrollView
        android:id="@+id/childScroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </ScrollView>

    <TextView
        android:id="@+id/solutions"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>
Posted by: Guest on November-07-2020

Code answers related to "android recyclerview adapter"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language