Class UserAdapter

java.lang.Object
androidx.recyclerview.widget.RecyclerView.Adapter<UserAdapter.UserViewHolder>
com.example.iconic_raffleevent.UserAdapter

public class UserAdapter extends androidx.recyclerview.widget.RecyclerView.Adapter<UserAdapter.UserViewHolder>
Adapter class for displaying a list of User objects in a RecyclerView. Utilizes ViewHolder pattern for efficient memory usage.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
    static class 
    ViewHolder class for holding the views for each item in the RecyclerView.
  • Constructor Summary

    Constructors
    Constructor
    Description
    UserAdapter(List<User> userList)
    Constructs a new UserAdapter with the provided list of users.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addUser(User user)
    Adds a new User to the list and notifies the adapter to refresh.
    void
    addUsers(List<User> users)
    Adds multiple users to the list and notifies the adapter.
    void
     
    int
    Returns the total number of items in the data set held by the adapter.
    void
    Binds data to the ViewHolder for the given position.
    onCreateViewHolder(android.view.ViewGroup parent, int viewType)
    Creates a new ViewHolder to represent an individual list item.
    void
     

    Methods inherited from class androidx.recyclerview.widget.RecyclerView.Adapter

    bindViewHolder, createViewHolder, getItemId, getItemViewType, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onAttachedToRecyclerView, onBindViewHolder, onDetachedFromRecyclerView, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycled, registerAdapterDataObserver, setHasStableIds, unregisterAdapterDataObserver

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • UserAdapter

      public UserAdapter(List<User> userList)
      Constructs a new UserAdapter with the provided list of users.
      Parameters:
      userList - the list of User objects to be displayed in the RecyclerView.
  • Method Details

    • setOnItemClickListener

      public void setOnItemClickListener(UserAdapter.OnItemClickListener listener)
    • addUser

      public void addUser(User user)
      Adds a new User to the list and notifies the adapter to refresh.
      Parameters:
      user - the User object to be added to the list.
    • onCreateViewHolder

      @NonNull public UserAdapter.UserViewHolder onCreateViewHolder(@NonNull android.view.ViewGroup parent, int viewType)
      Creates a new ViewHolder to represent an individual list item.
      Specified by:
      onCreateViewHolder in class androidx.recyclerview.widget.RecyclerView.Adapter<UserAdapter.UserViewHolder>
      Parameters:
      parent - the parent ViewGroup into which the new view will be added.
      viewType - the view type of the new view.
      Returns:
      a new UserViewHolder that holds a view for each user item.
    • onBindViewHolder

      public void onBindViewHolder(@NonNull UserAdapter.UserViewHolder holder, int position)
      Binds data to the ViewHolder for the given position. Loads the user's profile image using Glide if available; otherwise, loads a default image.
      Specified by:
      onBindViewHolder in class androidx.recyclerview.widget.RecyclerView.Adapter<UserAdapter.UserViewHolder>
      Parameters:
      holder - the ViewHolder in which data should be bound.
      position - the position of the item within the adapter's data set.
    • addUsers

      public void addUsers(List<User> users)
      Adds multiple users to the list and notifies the adapter.
      Parameters:
      users - the list of User objects to add.
    • clearUsers

      public void clearUsers()
    • getItemCount

      public int getItemCount()
      Returns the total number of items in the data set held by the adapter.
      Specified by:
      getItemCount in class androidx.recyclerview.widget.RecyclerView.Adapter<UserAdapter.UserViewHolder>
      Returns:
      the total number of users in the list.