title: How to set default fragment in android?
body: <p>I have tried several ways to set the default fragment as the 1st list item when app open's for the first time and last opened fragment when the app is not opened for the first time. But both scenarios are not working. Please help.</p>
  
  <pre><code>  mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                  int stupid, long id) {
              // getting values from selected ListItem
              name = ((TextView) view.findViewById(R.id.name))
                      .getText().toString();
              Strpath = ((TextView) view.findViewById(R.id.email))
                      .getText().toString();
              String description = ((TextView) view.findViewById(R.id.mobile))
                      .getText().toString();
              source_id = Integer.parseInt(description);
              // Starting single contact activity
              Bundle data = new Bundle();
              data.putString(TAG_NAME,name);
              data.putString(TAG_SOURCES, Strpath);
              Fragment fragment = new SingleContactActivity();
              fragment.setArguments(data);
              FragmentManager fragmentManager = getFragmentManager();
              fragmentManager.beginTransaction()
                      .replace(R.id.frame_container, fragment).commit();
              mDrawerLayout.closeDrawer(mDrawerList);
          }
      });
  new GetContacts().execute();
  </code></pre>
  
  <p>FMI, I didnt use switch case in my program. I have tried </p>
  
  <pre><code>mDrawerList.setSelection(0);
  </code></pre>
  
  <hr>
  
  <p>Here is my array list adapter </p>
  
  <pre><code> ListAdapter adapter = new SimpleAdapter(
                  MainActivity.this, navDrawerItems,
                  R.layout.list_item, new String[] { TAG_NAME, TAG_SOURCES,
                  TAG_ID }, new int[] { R.id.name,
                  R.id.email, R.id.mobile });
  </code></pre>
  
  <hr>
  
  <p>navDrawerItem , the item in the navdrawer is retrieve from MySQL</p>
  
  <pre><code> try {
                  JSONObject jsonObj = new JSONObject(jsonStr);
  
                  // Getting JSON Array node
                  contacts = jsonObj.getJSONArray(TAG_IPTV);
  
                  // looping through All Contacts
                  for (int i = 0; i &lt; contacts.length(); i++) {
                      JSONObject c = contacts.getJSONObject(i);
  
                      String id = c.getString(TAG_ID);
                      String name = c.getString(TAG_NAME);
                      String email = c.getString(TAG_SOURCES);
                      String address = c.getString(TAG_PACKAGE);
  
  
  
                      // tmp hashmap for single contact
                      HashMap&lt;String, String&gt; contact = new HashMap&lt;String, String&gt;();
  
                      // adding each child node to HashMap key =&gt; value
                      contact.put(TAG_ID, id);
                      contact.put(TAG_NAME, name);
                      contact.put(TAG_SOURCES, email);
                      contact.put(TAG_PACKAGE, address);
  
  
                      // adding contact to contact list
                      navDrawerItems.add(contact);
  
                  }
              } catch (JSONException e) {
                  e.printStackTrace();
  </code></pre>