KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Im trying to load an new fragment when a method is called. This method creates a new fragment and "replaces" the other fragment: private void showTestFragment(Fragment oldFragment, boolean addBackStack, BaseAdapter adapter, int position) { Cursor cursor = (Cursor)adapter.getItem(position); if(cursor != null){ int idx = cursor.getColumnIndexOrThrow(Episode._ID); long rowId = cursor.getLong(idx); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if(oldFragment != null){ Log.i(TAG, "Removing the old fragment"); fragmentTransaction.remove(oldFragment); } TestFragment testFragment = new TestFragment(); testFragment.setId(rowId); fragmentTransaction.add(android.R.id.content, testFragment); if(addBackStack){ Log.i(TAG, "Added to the backstack"); fragmentTransaction.addToBackStack(TAG); } fragmentTransaction.commit(); Fragment f = getFragmentManager() .findFragmentById(R.id.index); Log.i(TAG, "after commit, frag is "+ f); } } This works fine, until i go back. The last fragment, should be removed when i go back. Before i'm going to implement methods on the activities public void onBackPressed(){} to remove the last fragment, i want to know if i handle the fragment change correctly. It looks like i'm missing something here..
Tags (comma-separated)
Save Edits
Cancel