我已经设置在preference.xml文件中的两个按钮。我想去的主要活动,当我点击确定按钮。在这样的情况code是在哪里写的?
I have set the two buttons in preference.xml file. I want to go to main activity when I click the "ok" button. So for that code is where to write?
您可以设置在preferenceClickListener在preferenceActivity。
You can set an onPreferenceClickListener in your PreferenceActivity.
在preference的xml:
in preference xml :
<Preference android:title="Preference Button" android:summary="This works almost like a button" android:key="mypref" />
在preferences活动:
in preferences activity :
public class Preferences extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
// Get the custom preference
Preference mypref = (Preference) findPreference("mypref");
mypref.setOnPreferenceClickListener(new OnPreferenceClickListener() { });
}
}