Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A small framework to make using the 'ViewHolder' pattern a bit clearer

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 src
Octocat-spinner-32 .gitignore
Octocat-spinner-32 APACHE-LICENSE-2.0.txt
Octocat-spinner-32 README.md
Octocat-spinner-32 pom.xml
README.md

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:

listView.setAdapter(new ViewHoldingListAdapter<Foo>(fooList, viewInflatorFor(context, foo_list_item), new ViewHolderFactory<Foo>() {
    public ViewHolder<Foo> 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:

public class FooViewHolder implements ViewHolder<Foo> {
    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);
    }
}
Something went wrong with that request. Please try again.