Created
January 12, 2017 18:47
-
-
Save travisdachi/090caf09fb5c398b30b1c26ad0a16340 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class PersonAdapter extends RecyclerView.Adapter<PersonAdapter.PersonHolder> { | |
private List<Person> list; | |
public PersonAdapter(@NonNull List<Person> list) { | |
this.list = list; | |
} | |
@Override | |
public PersonHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_person, parent, false); | |
return new PersonHolder(view); | |
} | |
@Override | |
public void onBindViewHolder(PersonHolder holder, int position) { | |
Person person = list.get(position); | |
holder.textView.setText(String.format("%d %s(%d)", position, person.name, person.age)); | |
if (person.age >= 30) { | |
holder.textView.setTextColor(Color.RED); | |
} | |
} | |
@Override | |
public int getItemCount() { | |
return list.size(); | |
} | |
static class PersonHolder extends RecyclerView.ViewHolder { | |
public CheckBox checkBox; | |
public TextView textView; | |
public PersonHolder(View itemView) { | |
super(itemView); | |
checkBox = (CheckBox) itemView.findViewById(R.id.checkbox); | |
textView = (TextView) itemView.findViewById(R.id.text); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment