How do I programmatically add EditTextPreferences to my PreferenceFragment?

前端 未结 3 2117
北荒
北荒 2021-02-15 14:36

I am new to Android, so I need a little guidance on how to programmatically add EditTextPreference objects to my PreferenceFragment

3条回答
  •  难免孤独
    2021-02-15 15:07

    I don't know if it works in the onCreateView method but it does in the onViewCreated. Here is my code (Inside a subclass of PreferenceFragment):

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    
        this.getPreferenceScreen().addPreference(new EditTextPreference(getActivity()));
    }
    

提交回复
热议问题