title: How to reach the elements of the layout using PreferenceFragment?
body: <p>I've tried to make a custom preference layout, because I wanted to make a color picker with it.</p>
  
  <p>I used the solution <a href="http://developer.android.com/guide/topics/ui/settings.html#Fragment" rel="nofollow">here</a>:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      getFragmentManager().beginTransaction().replace(android.R.id.content, new PrefFragment()).commit();
  }
  </code></pre>
  
  <p>I wanted to edit the value of the TextView on the layout, that's why I added the lines with the TextView in it.</p>
  
  <p>The problem is that it threw a NullPointerException on the setText line, because I think the findViewById() method returned null.</p>
  
  <p>PrefFragment.java:</p>
  
  <pre><code>public class PrefFragment extends PreferenceFragment {
  
      private TextView titleTV;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          addPreferencesFromResource(R.xml.preferences);
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          titleTV = (TextView) getActivity().findViewById(R.id.title);
          titleTV.setText(R.string.pref_bgcolor);
      }
  }
  </code></pre>
  
  <p>preferences.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  &lt;Preference
      android:title="@string/pref_bgcolor"
      android:summary="@string/pref_bgcolor_sum"
      android:key="hu.atsoft.myip.color"
      android:widgetLayout="@layout/color_pref"/&gt;
  &lt;/PreferenceScreen&gt;
  </code></pre>
  
  <p>color_pref.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:id="@+id/color_preference"&gt;
  
      &lt;TextView
          android:id="@+id/title"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"
          android:layout_alignParentLeft="true"
          android:paddingLeft="5dip"
          android:paddingRight="5dip"
          android:paddingTop="5dip"
          android:singleLine="true"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:textColor="@android:color/black"/&gt;
  
      &lt;TextView
          android:id="@+id/summary"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:padding="5dip"
          android:layout_alignParentLeft="true"
          android:layout_below="@id/title"
          android:singleLine="true"
          android:textAppearance="?android:attr/textAppearanceSmall"/&gt;
  
      &lt;ImageView
          android:id="@+id/color_preview"
          android:layout_width="20dip"
          android:layout_height="20dip"
          android:background="@android:color/darker_gray"
          android:layout_alignParentRight="true"
          android:layout_centerVertical="true"
          android:layout_margin="5dip"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>What should I use to reach the elements instead of the findViewById() method?</p>