package net.somethingdreadful.MAL.adapters;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import net.somethingdreadful.MAL.Home;
import net.somethingdreadful.MAL.NavigationItems;
import net.somethingdreadful.MAL.R;

import java.util.ArrayList;

public class NavigationDrawerAdapter extends ArrayAdapter<NavigationItems.NavItem> {
    private ArrayList<NavigationItems.NavItem> items;
    private Home home;

    public NavigationDrawerAdapter(Home home, ArrayList<NavigationItems.NavItem> items) {
        super(home, R.layout.record_home_navigation, items);
        this.items = items;
        this.home = home;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;

        if (v == null) {
            LayoutInflater vi = home.getLayoutInflater();
            v = vi.inflate(R.layout.record_home_navigation, null);
        }

        NavigationItems.NavItem item = items.get(position);

        if (item != null) {
            ImageView mIcon = (ImageView) v.findViewById(R.id.nav_item_icon);
            TextView mTitle = (TextView) v.findViewById(R.id.nav_item_text);

            if (mIcon != null) {
                mIcon.setImageResource(item.icon);
            }
            if (mTitle != null) {
                mTitle.setText(item.title);
            }
        }

        return v;
    }
}
@@ -806,27 +806,17 @@
 n, View 
-convertView
+v
 , ViewGr
@@ -845,24 +845,25 @@
 View
- v = convertView
+Holder viewHolder
 ;%0A%0A 
@@ -1004,20 +1004,332 @@
 gation, 
-null
+parent, false);%0A%0A            viewHolder = new ViewHolder();%0A            viewHolder.mIcon = (ImageView) v.findViewById(R.id.nav_item_icon);%0A            viewHolder.mTitle = (TextView) v.findViewById(R.id.nav_item_text);%0A            v.setTag(viewHolder);%0A        %7D else %7B%0A            viewHolder = (ViewHolder) v.getTag(
 );%0A     
@@ -1394,17 +1394,16 @@
 ition);%0A
-%0A
         
@@ -1438,168 +1438,23 @@
     
-ImageView mIcon = (ImageView) v.findViewById(R.id.nav_item_icon);%0A            TextView mTitle = (TextView) v.findViewById(R.id.nav_item_text);%0A%0A            if (
+if (viewHolder.
 mIco
@@ -1482,16 +1482,27 @@
         
+viewHolder.
 mIcon.se
@@ -1558,16 +1558,27 @@
     if (
+viewHolder.
 mTitle !
@@ -1603,16 +1603,27 @@
         
+viewHolder.
 mTitle.s
@@ -1690,10 +1690,97 @@
 v;%0A    %7D
+%0A%0A    static class ViewHolder %7B%0A        ImageView mIcon;%0A        TextView mTitle;%0A    %7D
 %0A%7D

Add viewholder to the navigationdrawer (Adapter)