title: How do I programmatically add EditTextPreferences to my PreferenceFragment?
body: <p>I am new to Android, so I need a little guidance on how to <strong>programmatically</strong> add <strong>EditTextPreference</strong> objects to my <strong>PreferenceFragment</strong>.</p>
  
  <p>I am pulling in a list of values from a web service. I have saved them successfully to my <strong>SharedPreferences</strong>, and I use them to generate URLs (path portion). </p>
  
  <p>I would like the users of my app to be able to edit these values, but after lots of searching on Google, it isn't clear to me how to <strong>programmatically</strong> add <strong>EditTextPreference</strong> objects to my <strong>PreferenceFragment</strong>.</p>
  
  <p>Please note, my <strong>PreferenceFragment</strong> is working fine for the <strong>SharedPreferences</strong> values I hard code as names into the preference xml file (<strong>PreferenceScreen</strong>). I also know how to get my <strong>SharedPreferences</strong>, so don't worry about having to explain that portion to me.</p>
  
  <p>I use <strong>addPreferencesFromResource</strong> in <strong>onCreate</strong> of my <strong>PreferenceFragment</strong>. Should I add them in the <strong>onCreateView</strong>? I was thinking I could get the <strong>PreferenceCategory</strong> and add them there? But again, I am not sure how to do that. I would really be grateful for the help!</p>
  
  <p>// Code</p>
  
  <pre><code>PrefsFragment.java:
  package com.example.lorddoineedhelp;
  
  import android.os.Bundle;
  import android.preference.PreferenceFragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  public class PrefsFragment extends PreferenceFragment {
    @Override
    public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     addPreferencesFromResource(R.xml.preferences); 
    }
  
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View v = super.onCreateView(inflater, container, savedInstanceState); 
      // I am guessing I need to do something here?
      return v;
    }
  }
  </code></pre>
  
  <p>XML File for PreferenceFragment:</p>
  
  <pre><code>&lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    &lt;!-- Hard coded values --&gt;
    &lt;PreferenceCategory
            android:title="General"&gt;
      &lt;CheckBoxPreference
              android:key="debug"
              android:title="Debug"
              android:summary="Enable Debug" /&gt;
    &lt;/PreferenceCategory&gt;
    &lt;PreferenceCategory android:title="Address"&gt;
      &lt;EditTextPreference 
          android:key="ipAddress"
          android:title="IP Address"
          android:summary="IP Address used for Image pings"
      /&gt;
      &lt;EditTextPreference
            android:key="port"
            android:title="Port"
            android:summary="Port used for Image pings" /&gt;
    &lt;/PreferenceCategory&gt;
  
    &lt;!-- Where I want to add the values from my web service --&gt;
  
     &lt;PreferenceCategory 
         android:title="Paths"
         android:key="urlPaths"&gt;
    &lt;/PreferenceCategory&gt;
  &lt;/PreferenceScreen&gt;
  </code></pre>