I am trying to display custom preferences on clicking Settings options in the app. I have a listview in my MainActivity. On clicking settings, there is some INCOMPLETE VIEW displayed on top of MainActivity. And on clicking this view, the PreferenceFragment is visible with the settings layout. The listview scrolling gets disabled as a result of this view added on top of MainActivity.java. I need to display the PreferenceFragment as soon as Settings menu is clicked, instead of this incomplete view.
Please find my code below
MainActivity.java
MainActivity extends FragmentActivity{
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
}
}
}
PreferenceFragment.java
public class SettingsFragment extends PreferenceFragment{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
Any help is welcome !!