Package com.example.iconic_raffleevent
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 ClassesModifier and TypeClassDescriptionstatic interface
static class
ViewHolder class for holding the views for each item in the RecyclerView. -
Constructor Summary
ConstructorsConstructorDescriptionUserAdapter
(List<User> userList) Constructs a new UserAdapter with the provided list of users. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a new User to the list and notifies the adapter to refresh.void
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
onBindViewHolder
(UserAdapter.UserViewHolder holder, int position) 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
-
Constructor Details
-
UserAdapter
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
-
addUser
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 classandroidx.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
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 classandroidx.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
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 classandroidx.recyclerview.widget.RecyclerView.Adapter<UserAdapter.UserViewHolder>
- Returns:
- the total number of users in the list.
-