I am new to Android, so I need a little guidance on how to programmatically add EditTextPreference objects to my PreferenceFragment
Here is the code to create a PreferenceFragment programmatically:
public class MyPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(getActivity());
setPreferenceScreen(screen);
EditTextPreference preference = new EditTextPreference(screen.getContext());
preference.setKey("EditTextPreference");
preference.setTitle("Edit Text Preference");
preference.setSummary("Click the preference to edit text.");
screen.addPreference(preference);
}
}