Skip to content

Instantly share code, notes, and snippets.

@andrew-codechimp
Last active April 3, 2018 11:59
Show Gist options
  • Save andrew-codechimp/3351362 to your computer and use it in GitHub Desktop.
Save andrew-codechimp/3351362 to your computer and use it in GitHub Desktop.
[Launch Android Preference Fragment with only one header] #Android
// Handles the user's menu selection.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_settings:
@SuppressWarnings("rawtypes")
Class c = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? PreferencesActivity.class : FragmentPreferences.class;
Intent i = new Intent(this, c);
i.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT,
UserPreferencesFragment.class.getName());
i.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true);
startActivityForResult(i, SHOW_PREFERENCES);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment