Giter Site home page Giter Site logo

nageshkulkarni / wonderadapter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cesards/wonderadapter

0.0 1.0 0.0 3.65 MB

Small Android Library that let Developers write their own list adapters without copying code from previous projects

License: Apache License 2.0

wonderadapter's Introduction

WonderAdapter

How many times do you copy ArrayAdapter, CursorAdapter and ViewHolders code? I've developed this library based mostly on the idea of UniversalAdapter library, but I've implemented a few improvements like ViewHolder pattern, multi view and cursor compatibility.

Screenshots

Demo Screenshot

Usage

You just have to use the adapter that fits better to your needs. For now, there are only 3 wonder adapters you can use:

  • WArrayAdapter
  • WBaseAdapter
  • WCursorAdapter

Steps to use any of these adapters within a ListView:

  1. Create Custom Holder and let implement SingleWonder, MultiWonder or CursorWonder depending on the Adapter we want to use with. ..* T is the class of the item we want to show. ..* W the Holder class.
  2. Basic methods to implement (on single views): ..* W newInstance() returns an instance of W(holder) for every row in the list. Our holder contains row view fields initialized. ..* void bind(...) needed to draw desired object fields on the initialized view fields contained inside our class W. ..* View inflateView(...) needs explanation? :-).

Example: ListView with array list of items within a single row view

WArrayAdapter<Wonder, SingleViewHolder> adapter = new WArrayAdapter(this, getData(cursor), new SingleViewHolder());
listView.setAdapter(adapter);

and our SingleViewHolder implementation:

public class SingleViewHolder implements SingleWonder<Wonder, SingleViewHolder> {

  // UI
  @InjectView(R.id.row_wonder_image) ImageView imageView;
  @InjectView(R.id.row_wonder_title) TextView titleView;

  @Override public SingleViewHolder newInstance() {
    return new SingleViewHolder();
  }

  @Override public void bind(Context context, Wonder item) {
    Picasso.with(context).load(item.getImage()).into(imageView);
    titleView.setText(item.getTitle());
  }

  @Override public View inflateView(LayoutInflater inflater, ViewGroup parent) {
    View view = inflater.inflate(R.layout.row_wonder, parent, false);
    ButterKnife.inject(this, view);
    return view;
  }

}

I've used Jake Wharton's Butterknife library to avoid using findViewById on every view in our row layout :-)

Check the code for full demo samples.

Download

Not yet.

Download [the latest JAR][4] or grab via Maven:

<! -- Coming soon -->

or Gradle:

# Coming soon

TODO'S

  • CursorAdapter with multiple views support
  • My WMultiArrayAdapter extends Object for a reason. It's very possible to draw our headers from another list (having two separated array lists or more, depending the number of custom view rows we would like to use) I can discuss whether use Generics or Object...
  • I have to study carefully how to interact with other libraries, like StickyListHeaders, pinned-section-listview and other multi view ones.

Developed By

Follow me on Twitter Follow me on Google Plus Add me to Linkedin

License

Copyright 2014 DogmaLabs

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

wonderadapter's People

Contributors

cesards avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.