Android Open Source - android-drawerlayout Custom Drawer Adapter






From Project

Back to project page android-drawerlayout.

License

The source code is released under:

MIT License

If you think the Android project android-drawerlayout 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 com.tutecentral.navigationdrawer;
//  ww  w  .  j av a 2 s  .  c  o m
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomDrawerAdapter extends ArrayAdapter<DrawerItem> {

  Context context;
  List<DrawerItem> drawerItemList;
  int layoutResID;

  public CustomDrawerAdapter(Context context, int layoutResourceID,
      List<DrawerItem> listItems) {
    super(context, layoutResourceID, listItems);
    this.context = context;
    this.drawerItemList = listItems;
    this.layoutResID = layoutResourceID;

  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub

    DrawerItemHolder drawerHolder;
    View view = convertView;

    if (view == null) {
      LayoutInflater inflater = ((Activity) context).getLayoutInflater();
      drawerHolder = new DrawerItemHolder();

      view = inflater.inflate(layoutResID, parent, false);
      drawerHolder.ItemName = (TextView) view
          .findViewById(R.id.drawer_itemName);
      drawerHolder.icon = (ImageView) view.findViewById(R.id.drawer_icon);

      view.setTag(drawerHolder);

    } else {
      drawerHolder = (DrawerItemHolder) view.getTag();

    }

    DrawerItem dItem = (DrawerItem) this.drawerItemList.get(position);

    drawerHolder.icon.setImageDrawable(view.getResources().getDrawable(
        dItem.getImgResID()));
    drawerHolder.ItemName.setText(dItem.getItemName());

    return view;
  }

  private static class DrawerItemHolder {
    TextView ItemName;
    ImageView icon;
  }
}




Java Source Code List

com.example.android.navigationdrawerexample.MainActivity.java
com.example.drawersample.MainActivity.java
com.tutecentral.navigationdrawer.CustomDrawerAdapter.java
com.tutecentral.navigationdrawer.CustomDrawerAdapter.java
com.tutecentral.navigationdrawer.CustomSpinnerAdapter.java
com.tutecentral.navigationdrawer.DrawerItem.java
com.tutecentral.navigationdrawer.DrawerItem.java
com.tutecentral.navigationdrawer.FragmentOne.java
com.tutecentral.navigationdrawer.FragmentOne.java
com.tutecentral.navigationdrawer.FragmentThree.java
com.tutecentral.navigationdrawer.FragmentThree.java
com.tutecentral.navigationdrawer.FragmentTwo.java
com.tutecentral.navigationdrawer.FragmentTwo.java
com.tutecentral.navigationdrawer.MainActivity.java
com.tutecentral.navigationdrawer.MainActivity.java
com.tutecentral.navigationdrawer.SpinnerItem.java