Best way to implement a complex settings screen?

For my application, I have a rather complicated set of configuration options that the user can select. I am currently using PreferenceActivity as my user interface for these parameters, and the parameters are stored using common settings. As an example of some settings that I need to place:

  • Lists of pairs: to select a background image, the user can choose to use from 1 to 5 different shapes (where each shape is a .png file) and assign an int color to each shape. For example, a user may select an orange square, a green triangle, and a red rectangle.

  • Hierarchical data: one part of my application can be configured to use one of five modes. Each mode has several associated unique settings, for example. in one mode, you need to select two integers, for another mode, you may need to select one Boolean.

However, my feeling is: PreferenceActivity does not work with settings like the above, because:

  • General preferences cannot store lists.
  • General preferences cannot store hierarchical data.
  • Boiling my preferences interface up to, for example, individual preference buttons for adjusting each color and using dependent settings to disable preferences that are not applicable to the current mode, will create a messy and complex interface.

, , .

:

  • . , , .
  • XML Java. , , .

? , Android, , PreferenceActivity .

+3
1

Android, . , , , . , , . , , :

public class myprefs extends Activity{
private static final String PREFS_XML = "prefs_xml";
private static final String PREF_1 = "pref_1";

String preference;

private SharedPreferences preferences = null;
public void loadPrefs(){
    preferences = this.getSharedPreferences(PREFS_XML, Activity.MODE_PRIVATE);
    preference = preferences.getString(PREF_1, "default value");
}
}

, . ,

preferences.edit().putString(PREF_1, "hello!").commit();

onClick, onItemSelected "", . "" , . , . , , .

+1

Source: https://habr.com/ru/post/1789838/


All Articles