設定画面にボタンを付ける

設定画面にボタンを付けるためには、layoutを用意する必要があります。
PreferenceActivityの派生元はListActivitです。
用意するlayoutでListViewを用意することで、設定画面のレイアウトがListViewのところに適用されます。

#codeprettify{{

?xml version="1.0" encoding="utf-8"?>

LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical" >
   <ListView
       android:id="@android:id/list"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:layout_weight="1" >
   </ListView>
   <LinearLayout
       android:id="@+id/linearLayout1"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content" >
	    <Button
	        android:id="@+id/btnOK"
	        android:layout_width="wrap_content"
	        android:layout_height="wrap_content"
	        android:text="@string/lb_grp_btn_ok" />
	    <Button
	        android:id="@+id/btnCancel"
	        android:layout_width="wrap_content"
	        android:layout_height="wrap_content"
	        android:text="@string/lb_grp_btn_cancel" />
   </LinearLayout>

/LinearLayout> }}

レイアウトに追加するListViewのidは@android:id/listである必要があります。

で、PreferenceActivityの派生クラスでは、setContentView()メソッドで、layoutのxmlを指定します。

#codeprettify{{ class DemoActivity extends PreferenceActivity{

   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.prefarence_btn);
       addPreferencesFromResource(R.xml.prefarence);
       ・・・
   }

}}

参考


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2011-12-02 (金) 18:00:04