Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rtyley/android-viewholder-listviews
A small framework to make using the 'ViewHolder' pattern a bit clearer
https://github.com/rtyley/android-viewholder-listviews
Last synced: 23 days ago
JSON representation
A small framework to make using the 'ViewHolder' pattern a bit clearer
- Host: GitHub
- URL: https://github.com/rtyley/android-viewholder-listviews
- Owner: rtyley
- Created: 2011-04-13T12:59:14.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2020-10-12T19:54:23.000Z (about 4 years ago)
- Last Synced: 2024-10-13T14:35:17.203Z (about 1 month ago)
- Language: Java
- Homepage:
- Size: 44.9 KB
- Stars: 33
- Watchers: 5
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
The aim is to reduce the boilerplate around writing your own ListAdapter class. With the library, you define two smaller classes, a
ViewHolderFactory and a ViewHolder implementation.Here's how you would set the adapter on your listView:
```java
listView.setAdapter(new ViewHoldingListAdapter(fooList, viewInflatorFor(context, foo_list_item), new ViewHolderFactory() {
public ViewHolder createViewHolderFor(View view) {
return new FooViewHolder(view);
}
}));
```Your FooViewHolder just does the job of the ViewHolder - holds the references to the required Views, and populates those views with the relevant
fields from you Foo:```java
public class FooViewHolder implements ViewHolder {
private final TextView fooName,fooDate;
private final ImageView icon;public FooViewHolder(View v) {
this.avatarSession = avatarSession;
fooName = (TextView) v.findViewById(R.id.foo_item_name);
fooDate = (TextView) v.findViewById(R.id.foo_item_date);
icon = (ImageView) v.findViewById(R.id.foo_item_icon);
}public void updateViewFor(Foo foo) {
fooName.setText(foo.getName());
fooDate.setText(foo.getTimeString());
icon.setImageDrawable(iconBitmap);
}
}
```