FieldListViewAdapter
FieldListViewAdapter
is an abstract class that extends Android's BaseAdapter
that allows to easily have an adapter that accepts a Field<List<T>>
.
It effortlessly can be created through the FieldListViewAdapter.of
function. It accepts the following parameters:
items
: theField<List<T>>
containing the items we want to displayviewCreator
: a function that creates a view (of typeV
)viewBinder
: a function that, given a view of typeV
and an item of typeT
binds the item to the viewidProvider
: an optional function that provides unique IDs for the items. Defaults to callinghashCode()
An example:
//Assuming we have a class Movie and a MovieView with the method setMovie()
val movies : Field<List<Movie>> = getMovies()
listView.setAdapter(FieldListViewAdapter.of(
items = movies,
viewCreator = { MovieView(context) },
viewBinder = { view, movie -> view.setMovie(movie) },
idProvider = { movie -> movie.id }
))
//Assuming we have a class Movie and a MovieView with the method setMovie()
Field<List<Movie>> movies = getMovies();
listView.setAdapter(FieldListViewAdapter.of(
movies, //items
() -> new MovieView(getContext()), //viewCreator
(view, movie) -> view.setMovie(movie), //viewBinder
movie -> movie.getId() //idProvider
));