Android Open Source - TechDissected Nav Drawer Adapter

From Project

Back to project page TechDissected.


The source code is released under:

Apache License

If you think the Android project TechDissected 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.pkmmte.techdissected.adapter;
//from w w  w .  j a va 2 s  .  c om
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.pkmmte.pkrss.Category;
import com.pkmmte.techdissected.R;
import java.util.ArrayList;
import java.util.List;

public class NavDrawerAdapter extends BaseAdapter {
  // Essential Resources
  private final List<Category> mDrawerItems;
  private final Context mContext;

  // Current index and custom fonts
  private int currentPage;
  private int highlightColor;

  public NavDrawerAdapter(Context context) {
    this(context, new ArrayList<Category>());

  public NavDrawerAdapter(Context context, List<Category> drawerItems) {
    this.mDrawerItems = drawerItems;
    this.mContext = context;
    this.currentPage = 0;
    this.highlightColor = context.getResources().getColor(R.color.action_overlay);

  public void addItem(Category drawerItem) {

  public void setCurrentPage(int currentPage) {
    this.currentPage = currentPage;

  public int getCount() {
    return mDrawerItems.size();

  public Category getItem(int position) {
    return mDrawerItems.get(position);

  public long getItemId(int position) {
    return position;

  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;

    if (convertView == null) {
      LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView = mInflater.inflate(R.layout.drawer_item, parent, false);

      holder = new ViewHolder();
      holder.txtTitle = (TextView) convertView.findViewById(;

    else {
      holder = (ViewHolder) convertView.getTag();

    // Set text

    // Highlight if selected
    holder.txtTitle.setBackgroundColor((currentPage == position) ? highlightColor : Color.TRANSPARENT);

    return convertView;

  private class ViewHolder {
    public TextView txtTitle;

Java Source Code List