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: the Field<List<T>> containing the items we want to display
  • viewCreator: a function that creates a view (of type V)
  • viewBinder: a function that, given a view of type V and an item of type T binds the item to the view
  • idProvider: an optional function that provides unique IDs for the items. Defaults to calling hashCode()

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 ));