iNzzane iNzzane - 2 months ago 10
Android Question

Fragment placed on top of NavigationDrawer

I'm trying to add a

PreferenceFragment
in my application. The problem is, it's auto placed on top of my
NavigationDrawer
.

public class SetPreferenceActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
navigationDrawer(); // Loads the NavigationDrawer

getFragmentManager().beginTransaction().replace(android.R.id.content,
new Settings()).commit();

}


As you can see I load the "SettingsFragment" and replace the content with it? (I'm unsure) but it places it on top of everything else.. Here's my Settings fragment.

public class Settings extends PreferenceFragment {
static final String TAG = "MAIN";

@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);

}


Everything work as expected, BUT the PreferenceFragment are loaded in front, covering up the NavigationDrawer slideout, I tried calling
bringToFront();
on the listview, with no luck.

A picture for reference :



Is it possible to tell the fragment to load behind the listview? I also tought about loading the fragment in a ViewPager, but I get an error that the Pager Adapter wont accept fragments of type PreferenceFragment.

Answer

Don't replace android.R.id.content, use the the id of the FrameLayout you have in the layout that contains your DrawerLayout.