title: Nav Drawer List Adapter
body: <p>I'm gonna add you to my infinite item, but I can not, because when the number of items is too large, the program crashes and the items are moved and the list is not infinite. I'm grateful to help you public class NavDrawerListAdapter extends BaseAdapter {</p>
  
  <pre><code>    private Context context;
      private ArrayList&lt;NavDrawerItem&gt; navDrawerItems;
  
      public NavDrawerListAdapter(Context context, ArrayList&lt;NavDrawerItem&gt; navDrawerItems){
          this.context = context;
          this.navDrawerItems = navDrawerItems;
  
      }
  
      @Override
      public int getCount() {
          return navDrawerItems.size();
      }
  
      @Override
      public Object getItem(int position) {
          return navDrawerItems.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
  public View getView(int position, View convertView, ViewGroup parent) {
  
      if (convertView == null) {
          LayoutInflater mInflater = (LayoutInflater)
                  context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
  
          if (position == 0) {
              convertView = mInflater.inflate(R.layout.drawer_list_item_head, null);
          }
  
          else if (position == 7) {
              convertView = mInflater.inflate(R.layout.drawer_list_item_divider, null);
          }
          else if (position == 9) {
              convertView = mInflater.inflate(R.layout.drawer_list_item_divider, null);
          } else if (position == 11) {
              convertView = mInflater.inflate(R.layout.drawer_list_item_divider, null);
          }
          else if (position == 13) {
              convertView = mInflater.inflate(R.layout.drawer_list_item_divider, null);
          }
          else if (position == 15) {
              convertView = mInflater.inflate(R.layout.drawer_list_item_divider, null);
          }
  
          else {
              if (!Settings_Activity.loadNightMode(context)) {
                  convertView = mInflater.inflate(R.layout.drawer_list_item, null);
              } else {
                  convertView = mInflater.inflate(R.layout.drawer_list_item_dark, null);
              }
  
          }
      }
  
      if (position !=0&amp; position !=7&amp; position !=9&amp; position !=11&amp; position !=13&amp; position !=15) {
          ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon);
          TextViewPlus txtTitle = (TextViewPlus) convertView.findViewById(R.id.drawertitle);
  
          imgIcon.setImageResource(navDrawerItems.get(position).getIcon());
          txtTitle.setText(navDrawerItems.get(position).getTitle());
      }
  
  
      return convertView;
  }
  </code></pre>
  
  <p>public class NavConstructor {</p>
  
  <pre><code>public static int which_act;
  public static Context cc;
  public static Activity ac;
  public static ListView _mDrawerList;
  public static DrawerLayout _mDrawerLayout;
  public static int defpos;
  public static String[] _navMenuTitles;
  public static TypedArray _navMenuIcons;
  public static ArrayList&lt;NavDrawerItem&gt; _navDrawerItems;
  public static NavDrawerListAdapter _adapter;
  public static boolean intenthappennav = false;
  
  @SuppressWarnings("ResourceType")
  public static void Build(Context context, ListView mDrawerList,
                           DrawerLayout mDrawerLayout, int DEFAULT_POSITION) {
  
      _mDrawerList = mDrawerList;
      _mDrawerLayout = mDrawerLayout;
      cc = context;
      ac = (Activity) context;
      defpos = DEFAULT_POSITION;
      intenthappennav = false;
      _navMenuTitles = context.getResources().getStringArray(R.array.nav_drawer_items);
  
      // nav drawer icons from resources
      _navMenuIcons = context.getResources()
              .obtainTypedArray(R.array.nav_drawer_icons_dark);
  
      _navDrawerItems = new ArrayList&lt;NavDrawerItem&gt;();
      _navDrawerItems.add(new NavDrawerItem());
      _navDrawerItems.add(new NavDrawerItem(_navMenuTitles[1], _navMenuIcons.getResourceId(1, -1)));
      _navDrawerItems.add(new NavDrawerItem(_navMenuTitles[2], _navMenuIcons.getResourceId(2, -1)));
      _navDrawerItems.add(new NavDrawerItem(_navMenuTitles[3], _navMenuIcons.getResourceId(3, -1)));
      _navDrawerItems.add(new NavDrawerItem(_navMenuTitles[4], _navMenuIcons.getResourceId(4, -1)));
      _navDrawerItems.add(new NavDrawerItem(_navMenuTitles[5], _navMenuIcons.getResourceId(5, -1)));
      _navDrawerItems.add(new NavDrawerItem(_navMenuTitles[6], _navMenuIcons.getResourceId(6, -1)));
      _navDrawerItems.add(new NavDrawerItem());
      _navDrawerItems.add(new NavDrawerItem(_navMenuTitles[7], _navMenuIcons.getResourceId(7, -1)));
      _navDrawerItems.add(new NavDrawerItem());
      _navDrawerItems.add(new NavDrawerItem(_navMenuTitles[8], _navMenuIcons.getResourceId(8, -1)));
      _navDrawerItems.add(new NavDrawerItem());
      _navDrawerItems.add(new NavDrawerItem(_navMenuTitles[9], _navMenuIcons.getResourceId(9, -1)));
      _navDrawerItems.add(new NavDrawerItem());
      _navDrawerItems.add(new NavDrawerItem(_navMenuTitles[10], _navMenuIcons.getResourceId(10, -1)));
      _navDrawerItems.add(new NavDrawerItem());
      _navDrawerItems.add(new NavDrawerItem(_navMenuTitles[11], _navMenuIcons.getResourceId(11, -1)));
  
      _navDrawerItems.add(new NavDrawerItem(_navMenuTitles[12], _navMenuIcons.getResourceId(12, -1)));
  
      // Recycle the typed array
  
      _navMenuIcons.recycle();
  
      // setting the nav drawer list adapter
      _adapter = new NavDrawerListAdapter(context.getApplicationContext(), _navDrawerItems);
      mDrawerList.setAdapter(_adapter);
  
      mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
  }
  
  
  public static class SlideMenuClickListener implements
          ListView.OnItemClickListener {
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position,
                              long id) {
          displayView(position);
      }
  }
  
  public static void displayView(int position) {
      switch (position) {
  
          case 1:
              which_act = 1;
              break;
          case 2:
              which_act = 2;
              break;
          case 3:
              which_act = 3;
              break;
          case 4:
              which_act = 4;
              break;
          case 5:
              which_act = 5;
              break;
          case 6:
              which_act = 6;
              break;
          case 7:
              which_act = 7;
              break;
          case 8:
              which_act = 8;
              break;
          case 9:
              which_act = 9;
              break;
          case 10:
              which_act = 10;
              break;
          case 11:
              which_act = 11;
              break;
          case 12:
              which_act = 12;
              break;
          case 13:
              which_act = 13;
              break;
          case 14:
              which_act = 14;
              break;
          case 15:
              which_act = 15;
              break;
          case 16:
              which_act = 16;
              break;
          case 17:
              which_act = 17;
              break;
  
  
          default:
              break;
      }
      if (position != 0) {
  
          _mDrawerList.setItemChecked(position, true);
          _mDrawerList.setSelection(position);
          _mDrawerLayout.closeDrawer(_mDrawerList);
      } else {
          _mDrawerList.setItemChecked(defpos, true);
          _mDrawerList.setSelection(defpos);
      }
  
      NavigationClosed();
  }
  
  
  
  public static void NavigationClosed() {
  
      final Handler handler = new Handler();
      handler.postDelayed(new Runnable() {
          @Override
          public void run() {
              switch (which_act) {
                  case 0:
  
                      break;
  
                  case 1: //main menu
                      if (defpos != 1) {
                          intenthappennav = true;
                          Intent i1 = new Intent(cc, MainMenu.class);
                          ac.startActivity(i1);
                          ac.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
                          //ac.finish();
                      }
                      break;
                  case 2: //content
                      if (defpos != 2) {
                          intenthappennav = true;
                          Intent i2;
                          if (MainMenu.tabnum == 1) {
                              i2 = new Intent(cc, ContentMenu.class);
                          } else {
                              i2 = new Intent(cc, SeasonMenu.class);
                          }
                          ac.startActivity(i2);
                          ac.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
                          //ac.finish();
                      }
                      break;
                  case 3: // favorite
                      if (defpos != 3) {
                          intenthappennav = true;
                          Intent i3 = new Intent(cc, Favorites.class);
                          ac.startActivity(i3);
                          ac.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
                          //ac.finish();
                      }
  
                      break;
                  case 4: // search
                      if (defpos != 4) {
                          intenthappennav = true;
                          Intent i4 = new Intent(cc, Search_all.class);
                          i4.putExtra("nav", true);
                          i4.putExtra("defpos", defpos);
                          ac.startActivity(i4);
                          ac.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
                      }
  
                      break;
  
                  case 5: //settings
                      if (defpos != 5) {
                          intenthappennav = true;
                          Intent i6 = new Intent(cc, Settings_Activity.class);
                          ac.startActivity(i6);
                          ac.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
                          //ac.finish();
                      }
  
                      break;
  
                  case 6:  //aboutus
                      if (defpos != 6) {
                          intenthappennav = true;
                          Intent i7 = new Intent(cc, AboutUs.class);
                          ac.startActivity(i7);
                          ac.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
                          //ac.finish();
                      }
                      break;
                  case 7:
  
                      break;
                  case 8:  //aboutus
                      if (defpos != 8) {
                          intenthappennav = true;
                          Intent i9 = new Intent(cc, WebView1.class);
                          ac.startActivity(i9);
                          ac.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
                          //ac.finish();
                      }
                      break;
                  case 9:
  
                      break;
                  case 10:  //aboutus
                      if (defpos != 10) {
                          intenthappennav = true;
                          Intent i9 = new Intent(cc, WebView2.class);
                          ac.startActivity(i9);
                          ac.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
                          //ac.finish();
                      }
                      break;
                  case 11:
  
                      break;
                  case 12:  //aboutus
                      if (defpos != 12) {
                          intenthappennav = true;
                          Intent i9 = new Intent(cc, WebView3.class);
                          ac.startActivity(i9);
                          ac.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
                          //ac.finish();
                      }
                      break;
                  case 13:
  
                      break;
                  case 14:  //aboutus
                      if (defpos != 14) {
                          intenthappennav = true;
                          Intent i9 = new Intent(cc, WebView4.class);
                          ac.startActivity(i9);
                          ac.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
                          //ac.finish();
                      }
                      break;
                  case 15:
  
                      break;
                  case 16:  //aboutus
                      if (defpos != 16) {
                          intenthappennav = true;
                          Intent i9 = new Intent(cc, WebView5.class);
                          ac.startActivity(i9);
                          ac.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
                          //ac.finish();
                      }
                      break;
  
                  case 17:  //aboutus
                      if (defpos != 17) {
                          intenthappennav = true;
                          Intent i9 = new Intent(cc, WebView6.class);
                          ac.startActivity(i9);
                          ac.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
                          //ac.finish();
                      }
                      break;
  
  
              }
  
          }
      }, 250);
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>public class NavDrawerItem {</p>
  
  <pre><code>private String title;
  private int icon;
  
  
  
  public NavDrawerItem(String title, int icon){
      this.title = title;
      this.icon = icon;
  }
  
  public NavDrawerItem(){
  
  }
  
  
  public String getTitle(){
      return this.title;
  }
  
  public int getIcon(){
      return this.icon;
  }
  </code></pre>
  
  <p>}</p>