I have a Fragment with list of Contacts that is driven from API. Clicking on particular contact will go to Contact Detail Activity.The Problem now is, when clicking on the back arrow( ie., to go to the Contact List page) list is displayed from the first position rather than from last selected contact.But when clicking on back button in android device the last position is displayed.What might be the problem? Could anyone help me with this...
My Fragment Code
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_people_list, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mContactlistView = (ListView) view.findViewById(R.id.people_list);
mContactlistView.setAdapter(adapter);
if(state != null) {
Log.d(TAG, "trying to restore listview state..");
mContactlistView.requestFocus();
mContactlistView.onRestoreInstanceState(state);
}
indexLayout = (LinearLayout) view.findViewById(R.id.side_index);
}
@Override
public void onPause() {
Log.d(TAG, "saving listview state @ onPause");
state = mContactlistView.onSaveInstanceState();
super.onPause();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (mContactlistView.getAdapter() == null) {
adapter = new PeopleAdapter(getActivity().getApplicationContext(),
R.layout.people_list_item, contactList);
mContactlistView.setAdapter(adapter);
mContactlistView.setTextFilterEnabled(false);
mContactlistView.setFastScrollEnabled(true);
} else {
adapter.notifyDataSetChanged();
}
mContactlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String empId = String.valueOf(adapter.getItem(position).getEmployeeId());
String name = String.valueOf(adapter.getItem(position).getFirstName());
intent = new Intent(getActivity(),
PeopleDetailsActivity.class);
intent.putExtra("EmployeeId", empId);
intent.putExtra("name", name);
startActivity(intent);
}
});
startAsyncTask();
}