Android Open Source - NavigationDrawerSI Bindable Adapter






From Project

Back to project page NavigationDrawerSI.

License

The source code is released under:

Apache License

If you think the Android project NavigationDrawerSI listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package mmbialas.pl.navigationdrawersi.ui.misc;
/* w  w w .  ja v a 2 s  .  c o m*/
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

/** An implementation of {@link android.widget.BaseAdapter} which uses the new/bind pattern for its views. */
public abstract class BindableAdapter<T> extends BaseAdapter {
  private final Context context;
  private final LayoutInflater inflater;

  public BindableAdapter(Context context) {
    this.context = context;
    this.inflater = LayoutInflater.from(context);
  }

  public Context getContext() {
    return context;
  }

  @Override
  public abstract T getItem(int position);

  @Override
  public final View getView(int position, View view, ViewGroup container) {
    if (view == null) {
      view = newView(inflater, position, container);
      if (view == null) {
        throw new IllegalStateException("newView result must not be null.");
      }
    }
    bindView(getItem(position), position, view);
    return view;
  }

  /** Create a new instance of a view for the specified position. */
  public abstract View newView(LayoutInflater inflater, int position, ViewGroup container);

  /** Bind the data for the specified {@code position} to the view. */
  public abstract void bindView(T item, int position, View view);

  @Override
  public final View getDropDownView(int position, View view, ViewGroup container) {
    if (view == null) {
      view = newDropDownView(inflater, position, container);
      if (view == null) {
        throw new IllegalStateException("newDropDownView result must not be null.");
      }
    }
    bindDropDownView(getItem(position), position, view);
    return view;
  }

  /** Create a new instance of a drop-down view for the specified position. */
  public View newDropDownView(LayoutInflater inflater, int position, ViewGroup container) {
    return newView(inflater, position, container);
  }

  /** Bind the data for the specified {@code position} to the drop-down view. */
  public void bindDropDownView(T item, int position, View view) {
    bindView(item, position, view);
  }
}




Java Source Code List

mmbialas.pl.navigationdrawersi.ApplicationTest.java
mmbialas.pl.navigationdrawersi.data.Fragments.java
mmbialas.pl.navigationdrawersi.data.model.NavigationDrawerItem.java
mmbialas.pl.navigationdrawersi.ui.MainActivity.java
mmbialas.pl.navigationdrawersi.ui.fragments.FragmentAbout.java
mmbialas.pl.navigationdrawersi.ui.fragments.FragmentOne.java
mmbialas.pl.navigationdrawersi.ui.fragments.FragmentThree.java
mmbialas.pl.navigationdrawersi.ui.fragments.FragmentTwo.java
mmbialas.pl.navigationdrawersi.ui.misc.BetterViewAnimator.java
mmbialas.pl.navigationdrawersi.ui.misc.BindableAdapter.java
mmbialas.pl.navigationdrawersi.ui.navigationdrawer.NavigationDrawerAdapter.java
mmbialas.pl.navigationdrawersi.ui.navigationdrawer.NavigationDrawerItemView.java
mmbialas.pl.navigationdrawersi.ui.navigationdrawer.NavigationDrawerView.java