I was following this documentations to create a setting page. I have created two java classes based on the documentation:
SettingsFragment.java:
public static class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
}
...
}
SettingsActivity.java
public class SettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
}
In the preference I have an item with key premium_support
which I want to create a click listener for it.
<CheckBoxPreference
android:key="@string/premium_support"
android:title="Premium Support"
android:summary="Purchase premium support"
android:defaultValue="false" />
I can't create a click listener in the fragment because I have my in app billing codes in the SettingsActivity. I tried this answer but seems like findPreference
is only for the preferencefragment.
Any idea how to implement the click listener in SettingsActivity?