Android Open Source - NerdZoo Drawer Adapter






From Project

Back to project page NerdZoo.

License

The source code is released under:

Apache License

If you think the Android project NerdZoo 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.bignerdranch.android.nerdzoo.drawer;
/*from  w ww . j  av  a  2 s .c  o  m*/
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bignerdranch.android.nerdzoo.R;

import java.util.ArrayList;

public class DrawerAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<DrawerItem> mDrawerItems;
    private int mSelection;

    public DrawerAdapter(Context context, ArrayList<DrawerItem> drawerItems) {
        this.mContext = context;
        this.mDrawerItems = drawerItems;
        this.mSelection = 0;
    }

    @Override
    public int getCount() {
        return mDrawerItems.size();
    }

    @Override
    public Object getItem(int position) {
        return mDrawerItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.list_item_drawer, null);
        }
        DrawerItem drawerItem = mDrawerItems.get(position);

        ImageView icon = (ImageView) convertView.findViewById(R.id.list_item_drawer_icon);
        TextView title = (TextView) convertView.findViewById(R.id.list_item_drawer_title);

        icon.setImageResource(drawerItem.getIcon());
        title.setText(drawerItem.getTitle());
        title.setTextColor((position == mSelection) ? mContext.getResources().getColor(R.color.text_toolbar_primary) : mContext.getResources().getColor(R.color.text_primary));

        return convertView;
    }

    public void setSelection(int position) {
        mSelection = position;
    }

}




Java Source Code List

com.bignerdranch.android.nerdzoo.ApplicationTest.java
com.bignerdranch.android.nerdzoo.BaseApplication.java
com.bignerdranch.android.nerdzoo.BaseModule.java
com.bignerdranch.android.nerdzoo.anim.BaseItemAnimator.java
com.bignerdranch.android.nerdzoo.anim.PathAnimator.java
com.bignerdranch.android.nerdzoo.anim.RevealAnimator.java
com.bignerdranch.android.nerdzoo.anim.ZooItemAnimator.java
com.bignerdranch.android.nerdzoo.base.BaseActivity.java
com.bignerdranch.android.nerdzoo.base.BaseDrawerActivity.java
com.bignerdranch.android.nerdzoo.base.BaseNormalActivity.java
com.bignerdranch.android.nerdzoo.controller.AboutFragment.java
com.bignerdranch.android.nerdzoo.controller.AnimalActivity.java
com.bignerdranch.android.nerdzoo.controller.AnimalFragment.java
com.bignerdranch.android.nerdzoo.controller.MainActivity.java
com.bignerdranch.android.nerdzoo.controller.ZooFragment.java
com.bignerdranch.android.nerdzoo.drawer.DrawerAdapter.java
com.bignerdranch.android.nerdzoo.drawer.DrawerItem.java
com.bignerdranch.android.nerdzoo.model.Animal.java
com.bignerdranch.android.nerdzoo.model.Zoo.java
com.bignerdranch.android.nerdzoo.util.BuildUtils.java