Skip to content

Instantly share code, notes, and snippets.

@yujikosuga
Created September 22, 2011 08:05
Show Gist options
  • Save yujikosuga/1234287 to your computer and use it in GitHub Desktop.
Save yujikosuga/1234287 to your computer and use it in GitHub Desktop.
Add a button to a PreferenceScreen (Android)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_button);
...
Preference pref = findPreference("sample_key");
pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
// TODO Auto-generated method stub
return false;
}
});
...
}
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
...
<Preference
android:key="sample_key"
android:title="Button preference example"></Preference>
...
</PreferenceScreen>
@antosamalona
Copy link

Could you tell me where is I should make the file?

@mykhail0D
Copy link

thanks, it works for me

@jimandreas
Copy link

Thank you that was a good code hint. Works great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment