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.
mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> 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();
FMI, I didnt use switch case in my program. I have tried
mDrawerList.setSelection(0);
Here is my array list adapter
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 });
navDrawerItem , the item in the navdrawer is retrieve from MySQL
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
contacts = jsonObj.getJSONArray(TAG_IPTV);
// looping through All Contacts
for (int i = 0; i < 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<String, String> contact = new HashMap<String, String>();
// adding each child node to HashMap key => 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();