Simplify Adapter creation for your Android ListViews.

Related tags

Adapter FunDapter
Overview

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.


Now a more complicated text field:

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

	    @Override
	    public String getStringValue(Product item, int position) {
			return item.title;
	    }
	}).typeface(myBoldFace).visibilityIfNull(View.GONE);

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.


What about our image?? Lets add that as well:

prodDict.addDynamicImageField(R.id.productImage,
	new StringExtractor<Product>() {

	    @Override
	    public String getStringValue(Product item, int position) {
			return item.imageUrl;
	    }
	}, new DynamicImageLoader() {
	    @Override
	    public void loadDynamicImage(String url, ImageView view) {
			//insert your own async image loader implementation
	    }
	});

In here the StringExtractor grabs the URL from the Product item while the ImageLoader gives you a reference to the view and the URL you extracted so you can use your own custom lazy image loading implementation.


Finally, create the adapter:

FunDapter<Product> adapter = new FunDapter<Product>(getActivity(), productArrayList,
		R.layout.product_list_item, dict);

What is supported so far:

  • ViewHolder pattern and more performance optimizations
  • Switching data using funDapter.updateData()
  • Alternating background colors for the list items. Use funDapter.setAlternatingBackground()
  • Text fields:
    • typeface
    • visibility if null
    • changing textcolor based on a boolean condition - chain conditionalTextColor() when setting the field
  • Image fields (that load from the web)
  • ProgressBar fields - for showing user progress or xp.
  • Conditional visibility views - views that are shown or hidden according to some boolean value. (Good for decorations such as "sale" banners)
  • All fields support setting an OnClickListener by chaining onClick()
  • ExpandableListAdapter is supported

What next?

  • Support for ViewPagerAdapter
  • Support for Favorite toggle buttons (where you provide your own implementation for the data persistence)
  • Whatever else I can think of!

Gradle Support

Just add compile 'com.github.amigold.fundapter:library:1.0' to your dependencies in the build.gradle file in your project.

License

(The MIT License)

Copyright (c) 2012-2013 Ami Goldenberg [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • staticImageField question

    staticImageField question

    I have a question. I was looking to add an image from my res/drawable folder and not from url so i found this method addStaticImageField() but i dont know how to use it and there is no documentation or example on how it is used properly. Anything i could've missed?

    opened by geoplin 6
  • Get view from BindDictionary

    Get view from BindDictionary

    Hello! Can i get view from BindDictionary, for example there is visibilityIfNull, that can make my view invisible, but is there some mechanism, that in case that Integer is less than some threshold, i can make the TextView( with the integer number) red for example.

    opened by Mikelis 2
  • Manipulate view

    Manipulate view

    Is there a way to manipulate the view inside BindDictionary()?

    Or how can I add an click event for a image view for instance? Can I do this inside BindDictionary function?

    question 
    opened by devloe 2
  • onItemClickListener

    onItemClickListener

    Hi,

    I'm currently using FunDapter in a project, but I think I found a bug, and it's when I have a button and try to setOnItemClickListener, the clickEvent it's not being registered. Why is this happening?

    opened by NemesisDoom 1
  • Import Error in MyExpandableActivity AND missing support-v4 lib

    Import Error in MyExpandableActivity AND missing support-v4 lib

    MyExpandableActivity imports "com.ami.fundapter.ChildExtractor", this should be "com.ami.fundapter.extractors.ChildExtractor".

    Also support-v4 is missing in the libs folder

    opened by renevanderlende 1
  • Dependency error

    Dependency error

    Try to import and I get this error: Error:Module version com.github.amigold.fundapter:library:1.01 depends on libraries but is not a library itself

    Already added the support library.

    opened by fxsalazar 0
  • Where is ChildExtractor?

    Where is ChildExtractor?

    In the "MyExpandableActivity" of your "Sample", there is a "com.ami.fundapter.ChildExtractor" can't be resolved. Did you forget to commit it ?

    Of course, I've already checked the package "com.ami.fundapter" in the "library" project.

    My library is the version you commit at Sep 16, 2013. Thanks for your awesome work.

    opened by pcqpcq 0
  • how to use get filter for adapter

    how to use get filter for adapter

    hi i am using fundapter and show j son data in list view now i want to put a edit text and filter list view by inserting a text by user the method adapter.getfilter().filter () does not work for me i will appreciate if you help me what to do

    opened by davoodkaz 0
  • How to get the value of Object

    How to get the value of Object

    Hello Friend, i made this program to fetch data from Mysql database now i want to access the value of (**item.praveen)**object from which we fetch data from server. please tell me how to get the value of that object and use where i want.

    public void getuserType(){ String URL3 = "http://xyz/xyz/xyzs.php?user_id="+userName; PostResponseAsyncTask readData3 = new PostResponseAsyncTask(this, new AsyncResponse() { @Override public void processFinish(String u) { if (u.contains("Fail")) { Toast.makeText(newAdd.this, "Something went wrong sorry", Toast.LENGTH_SHORT).show(); } else { task3(ctx,u); } } }); readData3.execute(URL3); }

    public void task3(Context ctx,String u) {
        userd = new JsonConverter<userId>().toArrayList(u, userId.class);
        BindDictionary<userId> allReviews = new BindDictionary<userId>();
    
        allReviews.addStringField(R.id.tvUserId,
                new StringExtractor<userId>() {
                    @Override
                    public String getStringValue(userId item, int position) {
    
                        ///userValue.setText(item.praveen);
                        
                        **return item.praveen;**
                    }
                });
    
        FunDapter<userId> detailsAdapter = new FunDapter<>(newAdd.this, userd, R.layout.userid_single, allReviews);
        grid.setAdapter(detailsAdapter);
    
    }
    
    opened by PraveenGaur1987 0
  • hide any view from list

    hide any view from list

    how to hide any view from listview. kindly help me regarding this issue if any one knows the solution. otherwise suggest another way to set id and status of every list item. thank you.....

    opened by riz1ahmad 0
  • Identification question

    Identification question

    Hi,

    can you help me how to find a certain item's textView. For example I have a listView with some items and every item is made of 3 textViews (name, price, description). Now i want to change the value of the "price" textView with and updateView(int index) method. How do I identify the correct textView in the correct item?

    Let's say i have 5 items (product1, ..., product5). now i want to update the price of the 3rd product (product3). I call updateView(3) My updateView(int index) method so far

    private void updateView(int index){
            // thats how I get the row
            View v = lvProduct.getChildAt(index); 
            // here I want to find the tvPrice in that row
            // but I'm not sure how to go about this
    }
    
    opened by geoplin 0
  • Manifest merge for ic_launcher icon

    Manifest merge for ic_launcher icon

    Hi Ami, I used your library and found out that you used the ic_launcher icon as well. It wouldn't compile, unless I did a change with the icon or add xmlns:tools="http://schemas.android.com/tools" and tools:replace="android:icon". I made a blog about yours at http://www.kosalgeek.com/2015/09/fundapter-generic-adapter-custom-listview.html. Hope you fix it.

    opened by kosalgeek 0
Owner
Ami Goldenberg
Co-Founder & CTO @fairfly
Ami Goldenberg
Adapter Kit is a set of useful adapters for Android.

Adapter Kit Adapter Kit is a set of useful adapters for Android. The kit currently includes, Instant Adapter Instant Cursor Adapter Simple Section Ada

Ragunath Jawahar 368 Nov 25, 2022
Android library for the adapter view (RecyclerView, ViewPager, ViewPager2)

Antonio Android library for the adapter view (RecyclerView, ViewPager, ViewPager2) Free from implementation of the adapter's boilerplate code ! Reuse

NAVER Z 106 Dec 23, 2022
The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...

FastAdapter The FastAdapter is here to simplify creating adapters for RecyclerViews. Don't worry about the adapter anymore. Just write the logic for h

Mike Penz 3.7k Jan 8, 2023
An Adapter that allows a RecyclerView to be split into Sections with headers and/or footers. Each Section can have its state controlled individually.

⚠️ Archived: this repository is no longer going to be maintained. SectionedRecyclerViewAdapter An Adapter that allows a RecyclerView to be split into

Gustavo Pagani 1.7k Dec 21, 2022
A slim & clean & typeable Adapter without# VIEWHOLDER

PLEASE NOTE, THIS PROJECT IS NO LONGER BEING MAINTAINED First At A Glance :) Intro A slim & clean & typeable Adapter without# VIEWHOLDER Features No V

lin 940 Dec 30, 2022
Create a new adapter for a RecyclerView or ViewPager is now much easier.

Efficient Adapter for Android Create a new adapter for a RecyclerView or ViewPager is now much easier. Overview Create a list of elements into a Recyc

Stan Kocken 423 Sep 16, 2022
Small, smart and generic adapter for recycler view with easy and advanced data to ViewHolder binding.

smart-recycler-adapter Never code any boilerplate RecyclerAdapter again! This library will make it easy and painless to map your data item with a targ

Manne Öhlund 405 Dec 30, 2022
Rx based RecyclerView Adapter

RxRecyclerAdapter Rx based generic RecyclerView Adapter Library. How to use it? Example! Enable Databinding by adding these lines to your build.gradle

Ahmed Rizwan 193 Jun 18, 2022
This Repository simplifies working with RecyclerView Adapter

AutoAdapter This Repository simplifies working with RecyclerView Adapter Gradle: Add it in your root build.gradle at the end of repositories: allproj

George Dzotsenidze 151 Aug 15, 2021
Generic RecyclerView adapter

Generic RecyclerView Adapter. Lightweight library which simplifies creating RecyclerView adapters and illuminates writing boilerplate code. Creating a

Leonid Ustenko 77 Dec 24, 2022
This library provides GridAdapters(ListGridAdapter & CursorGridAdapter) which enable you to bind your data in grid card fashion within android.widget.ListView, Also provides many other features related to GridListView.

GridListViewAdapters This libarary enables you to implement GridView like card layout within ListView with added capabilites like Paginations, Additio

Biraj Patel 270 Nov 25, 2022
Just like instant coffee, saves 78% of your time on Android's Custom Adapters.

Notice Instant Adapter is now part of an even more awesome Adapter Kit project! Instant Adapter Just like instant coffee, saves 78%* of your time on A

Ragunath Jawahar 232 Nov 25, 2022
Vector map library and writer - running on Android and Desktop.

Mapsforge See the integration guide and changelog. And read through how to contribute guidelines. If you have any questions or problems, don't hesitat

mapsforge 1k Jan 2, 2023
Epoxy is an Android library for building complex screens in a RecyclerView

Epoxy Epoxy is an Android library for building complex screens in a RecyclerView. Models are automatically generated from custom views or databinding

Airbnb 8.1k Jan 4, 2023
Renderers is an Android library created to avoid all the boilerplate needed to use a RecyclerView/ListView with adapters.

Renderers Renderers is an Android library created to avoid all the RecyclerView/Adapter boilerplate needed to create a list/grid of data in your app a

Pedro Vicente Gómez Sánchez 1.2k Nov 19, 2022
Android library to auto-play/pause videos from url in recyclerview.

AutoplayVideos Show some ❤️ and star the repo to support the project This library is created with the purpose to implement recyclerview with videos ea

Krupen Ghetiya 989 Nov 17, 2022
:page_with_curl: [Android Library] Giving powers to RecyclerView

Android library that provides most common functions around recycler-view like Swipe to dismiss, Drag and Drop, Divider in the ui, events for when item

Nishant Srivastava 644 Nov 20, 2022
[] Easy Adapters library for Android

Deprecated Due to the growing use of the RecyclerView and the RecyclerView.Adapter provided adapter class, Easy-Adapter is now deprecated. Whilst the

ribot 425 Nov 25, 2022
Generate data-view-binding adapters of android recycler view.

Items 这个库可以为 Android 的 RecyclerView 生成基于 Data-View-Binding 的 Adapter。 对比其他一些类似的开源库,它有以下的一些优势: 更好的拓展性。这个库不需要你继承特定的 Adapter 或 ViewHolder 类,你可以继承任何第三方提供的

nekocode 253 Nov 11, 2022