CreatioSoft Company
- Forum posts: 8
Oct 16, 2012, 2:29:07 PM via Website
Oct 16, 2012 2:29:07 PM via Website
PreferenceActivity -This is the base class for an activity to show a hierarchy of preferences to the user. It is usually used to create a standard looking settings screen for any application.
The values are stored in SharedPreferences automatically by the PreferenceActivity.
The list of settings, are defined in xml file in xml folder which is inside the res folder.
The given example explains its usage.
Now, this class extends PreferenceActivity implements OnPreferenceChangeListener.When ever the preference value is changed the OnPreferenceClickListener is used to do the required action.
public class SettingActivity extends PreferenceActivity implements
Preference.OnPreferenceChangeListener {
static ChartBoost cb;
String TAG = "chartboost";
Preferences preferences;
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setting_screen);// list view
addPreferencesFromResource(R.xml.settings);// adding preferences
}
//fetching the required prefereence
final Preference prefimg = (Preference) findPreference("picture");
//setting PreferenceClickListener on the preference prefimg.setOnPreferenceClickListener(new OnPreferenceClickListener() {
// if select background is selected
public boolean onPreferenceClick(Preference preference) {
//preference clicked
Intent i = new Intent(SettingActivity.this, GalleryView.class );
startActivity(i);
// put your code here
return true;
}
Similarly , you can add action code whenever there is click on the preference setting.
The values are stored in SharedPreferences automatically by the PreferenceActivity.
The list of settings, are defined in xml file in xml folder which is inside the res folder.
The given example explains its usage.
Now, this class extends PreferenceActivity implements OnPreferenceChangeListener.When ever the preference value is changed the OnPreferenceClickListener is used to do the required action.
public class SettingActivity extends PreferenceActivity implements
Preference.OnPreferenceChangeListener {
static ChartBoost cb;
String TAG = "chartboost";
Preferences preferences;
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setting_screen);// list view
addPreferencesFromResource(R.xml.settings);// adding preferences
}
//fetching the required prefereence
final Preference prefimg = (Preference) findPreference("picture");
//setting PreferenceClickListener on the preference prefimg.setOnPreferenceClickListener(new OnPreferenceClickListener() {
// if select background is selected
public boolean onPreferenceClick(Preference preference) {
//preference clicked
Intent i = new Intent(SettingActivity.this, GalleryView.class );
startActivity(i);
// put your code here
return true;
}
Similarly , you can add action code whenever there is click on the preference setting.
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.