Created
March 7, 2018 20:34
-
-
Save nikolajakshic/fd4b0ff139c8da1afa17d5fe0bb2f281 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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