title: Clicking on navigation drawer close itself Android studio
body: <p>I have implemented navigation drawer on my mobile application and whenever i open the drawer and click on the drawer, the drawer closes itself. It used to work perfectly until I implemented another function and I am puzzled about how I should fix this.
  Here's my main activity code. I am unable to navigate using the navigation drawer now.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>package com.example.admin.calendlist;
  
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.graphics.PorterDuff;
  import android.graphics.drawable.Drawable;
  import android.support.annotation.NonNull;
  import android.support.design.widget.NavigationView;
  import android.support.v4.view.GravityCompat;
  import android.support.v4.widget.DrawerLayout;
  import android.support.v7.app.ActionBarDrawerToggle;
  import android.support.v7.app.AlertDialog;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.ArrayAdapter;
  import android.widget.EditText;
  import android.widget.ListView;
  import android.widget.TextView;
  
  import java.util.ArrayList;
  
  public class MainActivity extends AppCompatActivity  {
      private DrawerLayout mDrawerLayout;
      private ActionBarDrawerToggle mToggle;
      DatabaseHelper dbHelper;
      ArrayAdapter&lt;String&gt; mAdapter;
      ListView lstTask;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer);
          mToggle = new ActionBarDrawerToggle(this,mDrawerLayout, R.string.open,R.string.close);
          mDrawerLayout.addDrawerListener(mToggle);
          mToggle.syncState();
          dbHelper = new DatabaseHelper(this);
          lstTask = (ListView)findViewById(R.id.lstTask);
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
          NavigationView nvDrawer = (NavigationView)findViewById(R.id.nav_view);
          setupDrawerContent(nvDrawer);
          loadTaskList();
  
      }
  
      private void loadTaskList() {
          ArrayList&lt;String&gt; taskList = dbHelper.getTaskList();
          if(mAdapter==null){
              mAdapter = new ArrayAdapter&lt;String&gt;(this, R.layout.row,R.id.task_title,taskList);
              lstTask.setAdapter(mAdapter);
          }
          else{
              mAdapter.clear();
              mAdapter.addAll(taskList);
              mAdapter.notifyDataSetChanged();
          }
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          if (mToggle.onOptionsItemSelected(item)){
              return true;
          }
           {
              switch (item.getItemId()) {
               case R.id.action_add_task:
                   final EditText taskEditText = new EditText(this);
                   AlertDialog dialog = new AlertDialog.Builder(this)
                           .setTitle("Add New Task")
                           .setMessage("What do you want to do next?")
                           .setView(taskEditText)
                           .setPositiveButton("Add", new DialogInterface.OnClickListener() {
                               @Override
                               public void onClick(DialogInterface dialog, int which) {
                                   String task = String.valueOf(taskEditText.getText());
                                   dbHelper.insertNewTask(task);
                                   loadTaskList();
                               }
                           })
                           .setNegativeButton("Cancel", null)
                           .create();
                   dialog.show();
           }
               switch (item.getItemId()) {
                   case R.id.td:
                       Intent newIntent = new Intent(this,MainActivity.class);
                       return true;
               }
               switch (item.getItemId()) {
                   case R.id.tt:
                       Intent newIntent = new Intent(this,Timetable.class);
                       return true;
               }
               switch (item.getItemId()) {
                   case R.id.ep:
                       Intent newIntent = new Intent(this,EventPage.class);
                       return true;
               }
          }
          return super.onOptionsItemSelected(item);
      }
  
      private void selectItemDrawer(MenuItem item) {
          int id = item.getItemId();
           if (id ==R.id.ep) {
               Intent newItent = new Intent (this, EventPage.class);
               startActivity(newItent);
           }
           else if (id == R.id.td) {
               Intent newIntent = new Intent (this,MainActivity.class);
               startActivity(newIntent);
           }
           else if (id == R.id.tt) {
               Intent newIntent = new Intent (this,Timetable.class);
               startActivity(newIntent);
           }
           DrawerLayout drawer = findViewById(R.id.drawer);
           drawer.closeDrawer(GravityCompat.START);
      }
      private void setupDrawerContent (NavigationView navigationView) {
          navigationView.setNavigationItemSelectedListener (new NavigationView.OnNavigationItemSelectedListener() {
              @Override
              public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                  selectItemDrawer(item);
                  return true;
              }
          });
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.listmenu,menu);
          Drawable icon =menu.getItem(0).getIcon();
          icon.mutate();
          icon.setColorFilter(getResources().getColor(android.R.color.black), PorterDuff.Mode.SRC_IN);
          return super.onCreateOptionsMenu(menu);
      }
  
      public void deleteTask(View view){
          View parent = (View)view.getParent();
          TextView taskTextView = (TextView)findViewById(R.id.task_title);
          String task = String.valueOf(taskTextView.getText());
          dbHelper.deleteTask(task);
          loadTaskList();
      }
  
  }</code></pre>
  </div>
  </div>
  </p>