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
recyclerView.setAdapter(new ContactsAdapter(this, contacts)); |
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 int getItemCount() { | |
return this.contacts.size(); | |
} |
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(ViewHolder holder, int position) { | |
Contact contact = contacts.get(position); | |
holder.nameTextView.setText(contact.getName()); | |
holder.mobileTextView.setText(contact.getMobile()); | |
holder.landlineTextView.setText(contact.getLandline()); | |
} |
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 ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
return new ViewHolder( | |
LayoutInflater | |
.from(context) | |
.inflate(R.layout.contact_item, parent, false) | |
); | |
} |
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
this.context = context; |
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
public class ViewHolder extends RecyclerView.ViewHolder { | |
private TextView nameTextView; | |
private TextView mobileTextView; | |
private TextView landlineTextView; | |
public ViewHolder(@NonNull View view) { | |
super(view); | |
this.nameTextView = (TextView)view | |
.findViewById(R.id.name_text_view); | |
this.mobileTextView = (TextView)view |
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
public class ContactsAdapter extends RecyclerView.Adapter<ContactsAdapter.ViewHolder> { |
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
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list); |
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
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:id="@+id/list" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:divider="@null" | |
tools:context="com.spreys.viewholderexample.ListViewActivity" /> |
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
compile 'com.android.support:recyclerview-v7:25.3.1' |