Skip to content

Instantly share code, notes, and snippets.

@nikolajakshic
Created March 7, 2018 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikolajakshic/fd4b0ff139c8da1afa17d5fe0bb2f281 to your computer and use it in GitHub Desktop.
Save nikolajakshic/fd4b0ff139c8da1afa17d5fe0bb2f281 to your computer and use it in GitHub Desktop.
@Override
public void onBindViewHolder(RecViewHolder holder, int position) {
Movie movie = list.get(position);
// Set movie data
holder.bind(movie);
holder.itemView.setOnClickListener(v -> {
// Get the current state of the item
boolean expanded = movie.isExpanded();
// Change the state
movie.setExpanded(!expanded);
// Notify the adapter that item has changed
notifyItemChanged(position);
});
}
// Method in ViewHolder class
private void bind(Movie movie) {
// Get the state
boolean expanded = movie.isExpanded();
// Set the visibility based on state
subItem.setVisibility(expanded ? View.VISIBLE : View.GONE);
title.setText(movie.getTitle());
genre.setText("Genre: " + movie.getGenre());
year.setText("Year: " + movie.getYear());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment