I came to the activity class as for need from an fragment and now I want to go back to my earlier fragment.But The fragment was came from an drawer layout.I can't understand what to do....
here is my code.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_answered, container, false);
GridView answeredGridView = (GridView) view.findViewById(R.id.answeredQuestiongridview);
answeredImageAdapter = new AnsweredImageAdapter(getActivity());
answeredImageAdapter.notifyDataSetChanged();
answeredGridView.invalidateViews();
answeredGridView.setAdapter(answeredImageAdapter);
answeredImageAdapter.notifyDataSetChanged();
answeredGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getActivity()," "+position,Toast.LENGTH_SHORT).show();
questionposition = position;
Intent intent = new Intent(getActivity(), AnswerDetailsActivity.class);
intent.putExtra("Image_position",position);
intent.putExtra("question_id",id);
startActivity(intent);
getActivity().finish();
}
});
return view;
}
Suppose now I am in this activity page. and want to go back to my fragment page..I wrote following code and facing the app is unfortunately stopped.
private void answerFragment() {
answeredFragment = new AnsweredFragment();
fragmentManager = getSupportFragmentManager();
//answeredFragment = fragmentManager.findFragmentById("myFragment");
android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.main_fragment_container,answeredFragment);
fragmentTransaction.commit();
}