title: Adding PreferenceScreen to linearlayout
body: <p>Hi I am new to Android and Java and have run into a problem. My problem is that i am trying to add a PreferenceScreen to my linear layout so I am able to set an <code>setOnSeekBarChangeListener()</code> on the seekbar in <strong>res/layout/activity_main.xml</strong>. At the moment the PreferenceScreen and the LinearLayout get added to the view but they are on top of each other which is not what I want. Instead I want the PreferenceScreen to go in place of the ListView inside my layout file.</p>
  
  <p><strong>res/xml/settings.xml</strong></p>
  
  <pre><code>&lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;PreferenceCategory
          android:title="Category"
          android:key="category_preference"&gt;
          &lt;SwitchPreference
              android:key="switch_preference"
              android:title="Title"
              android:summary="Summary"
              android:defaultValue="true" /&gt;
  
          &lt;CheckBoxPreference
              android:key="checkbox_preference"
              android:title="Title"
              android:summary="Summary"
              android:defaultValue="true" /&gt;
      &lt;/PreferenceCategory&gt;
  &lt;/PreferenceScreen&gt;
  </code></pre>
  
  <p><strong>res/layout/activity_main.xml</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="fill_parent"
      android:orientation="vertical"
      android:layout_height="fill_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".MainActivity" &gt;
  
      &lt;SeekBar
          android:id="@+id/main_seek_bar"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" /&gt;
  
      &lt;ListView android:id="@android:id/list"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends Activity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
          setContentView(R.layout.activity_main);
  
          SeekBar seekBar = (SeekBar) findViewById(R.id.main_seek_bar);
  
          seekBar.setOnTouchListener(new SeekBar.OnTouchListener() {
              @Override
              public boolean onTouch(View arg0, MotionEvent arg1) {
                  // TODO Auto-generated method stub
                  return false;
              }
          });
      }
  
      public static class SettingsFragment extends PreferenceFragment implements OnSharedPreferenceChangeListener {
          public static final String KEY_PREF_SYNC_CONN = "pref_syncConnectionType";
  
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              addPreferencesFromResource(R.xml.settings);
              onSharedPreferenceChanged(null, "");
          }
  
          @Override
          public void onResume() {
              super.onResume();
              getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
          }
  
          @Override
          public void onPause() {
              super.onPause();
              getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
          }
  
          @Override
          public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
              if (key.equals("switch_preference")) {
                  Toast.makeText(getActivity(), "Switch", Toast.LENGTH_LONG).show();
              }
          }
      }
  }
  </code></pre>