Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/turskyi/viewholderexample

This project demonstrates the basic usage of a RecyclerView with ViewHolder to display a list of items.
https://github.com/turskyi/viewholderexample

android educational kotlin recyclerview sample-app viewholder xml

Last synced: 27 days ago
JSON representation

This project demonstrates the basic usage of a RecyclerView with ViewHolder to display a list of items.

Awesome Lists containing this project

README

        

[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct-single.svg)](https://stand-with-ukraine.pp.ua)
GitHub commit activity

# Android RecyclerView Sample

This project demonstrates the basic usage of a RecyclerView to display a list
of items. It showcases the following:

- **Creating and setting up a RecyclerView**:
- Defining the RecyclerView in your layout XML file.
- Finding the RecyclerView reference in your Activity or Fragment.
- Setting a LayoutManager (e.g., LinearLayoutManager for vertical or
horizontal lists).
- Creating and setting an adapter (GreenAdapter in this case).
- **Implementing a RecyclerView.Adapter**:
- Creating a custom adapter class that extends RecyclerView.Adapter.
- Defining a ViewHolder to hold references to the views in each list item.
- Overriding onCreateViewHolder to inflate the item layout and create
ViewHolder instances.
- Overriding onBindViewHolder to populate the views in each ViewHolder with
data.
- Overriding getItemCount to return the total number of items in the list.
- **Handling item clicks**:
- Defining an interface (ListItemClickListener) for click callbacks.
- Implementing the interface in your Activity or Fragment.
- Setting up click listeners in your ViewHolder.
- Triggering the callback in the onClick method of your ViewHolder.
- **ViewHolder recycling and reuse**:
The example visually demonstrates how ViewHolders are recycled by assigning
different background colors to each ViewHolder instance. As you scroll,
you'll see the colors get reused, illustrating the recycling mechanism.
This sample project can be a valuable resource for developers learning to use
RecyclerView in their Android applications.

## Contact:

For any inquiries or suggestions, please open an issue on the GitHub repository
or reach out to me directly at
[[email protected]](mailto:[email protected]).

## Screenshot:

screenshot