FunDapter

Additional

Language
Java
Version
N/A
Created
May 15, 2013
Updated
Oct 1, 2014 (Retired)
Owner
Ami Goldenberg (amigold)
Contributors
dan (dbachelder)
Ami Goldenberg (amigold)
AmiGoldMoblin
3
Activity
Badge
Generate
Download
Source code

Blurb

FunDapter takes the pain and hassle out of creating a new Adapter class for each ListView you have in your Android app.

It is a new approach to custom adapter creation for Android apps. You get free ViewHolder pattern support, field validation so you don't get bit by trivial bugs and best of all - you get to keep it DRY!

What's new?

  1. Gradle support now only contains a JAR archive instead of AAR which wasn't needed. Just add compile 'com.github.amigold.fundapter2:library:1.01' to your dependencies in the build.gradle file in your project.

What you used to do:

  1. Subclass BaseAdapter or copy existing adapter you already wrote.
  2. Create a ViewHolder static class a define all the views in it.
  3. Write (Copy.. don't fool yourself!) the whole ViewHolder creation code from somewhere.
  4. Write all the "findViewById" lines.
  5. Start filling data in the views inside the getView method.

Well that was boring! I feel your pain!

What FunDapter lets you do:

  1. Create a new BindDictionary
  2. Add fields.
  3. Create a new FunDapter instance, supplying the BindDictionary, layout resource file and item list.

Getting Started

This is the Product class we'll create an adapter for:

public class Product {
 
 public String title;
 public String description;
 public String imageUrl;
 public double price;
}

Create a new BindDictionary instance:

BindDictionary<Product> dict = new BindDictionary<Product>();

Adding a basic text field:

dict.addStringField(R.id.description,
 new StringExtractor<Product>() {

     @Override
     public String getStringValue(Product item, int position) {
   return item.description;
     }
 });

Notice how you simply provide the id of the TextView and an implementation of the StringExtractor which will be used to get the correct String value from your Product.


Notice how you can chain calls to get some more complex behaviours out of your views. typeface() will set a typeface on the view while visibilityIfNull() will change the visibility of the field according to the value being null or not.