Preference を任意のレイアウトにする

Preference レイアウトを PreferenceActivity に任せるのではなく、
任意のレイアウト、つまり、PreferenceActivity を継承しつつ、setContentView で任意レイアウトを
指定する場合、

任意レイアウトの中の Preference のレイアウトは、
  Listview で、 android:id="@android:id/list" とした ListView になる。

任意レイアウトでは、必ずこれ1つである。

<ListView
      android:id="@android:id/list"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_weight="1" >
</ListView>

<LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="center_horizontal"
      android:gravity="center_horizontal"
      android:orientation="horizontal"
      android:background="@android:drawable/bottom_bar" >

<Button
      android:id="@+id/backButton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="BACK" />

</LinearLayout>

と、書けば、PreferenceActivity 継承クラスで
setContentView でこのレイアウトを指定して


addPreferencesFromResource(R.xml.preference);

final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

*1.setOnClickListener(new View.OnClickListener(){
   @Override
   public void onClick(View v){
      finish();
   }
});

というように、書ける。

*1:Button)findViewById(R.id.backButton