PreferenceActivityにボタンを提供したいと思います。ユーザーは(たとえばTimePickerを介して)時間を設定できるはずですが、ButtonPreferenceなどはありません。EditTextPreferenceを使用したくありません。
では、PreferenceActivityでデフォルトのボタンを使用して、その設定を手動で保存する必要がありますか?
よろしく、
cody
PreferenceActivityにボタンを提供したいと思います。ユーザーは(たとえばTimePickerを介して)時間を設定できるはずですが、ButtonPreferenceなどはありません。EditTextPreferenceを使用したくありません。
では、PreferenceActivityでデフォルトのボタンを使用して、その設定を手動で保存する必要がありますか?
よろしく、
cody
ウィジェットDialogPreference
を組み込んだカスタムを作成します。TimePicker
ボタンは必要ありません。100行未満のコードである必要があります。
これは、特にカスタムを示すサンプルプロジェクトColorPreference
です。
Create a different layout including your custom controls and include ListView on top, see the example below
// extra_settings.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"/>
<TextView
android:id="@+id/feedback"
android:text="Feedback"
/>
<Button
android:id="@+id/about"
android:text="About"
/>
</LinearLayout>
Once this done, onCreate method of your class which is extended from PreferenceActivity add following line
setContentView(R.layout.settings_extras); //name of your layout
bind OnClickListener
View.OnClickListener feedbackPageRedirect = new View.OnClickListener()
{
public void onClick(View v)
{
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback ");
startActivity(emailIntent);
}
};
ボタンはactivity_layout.xmlに配置できます。たとえば、「Activity_Setup.java」がセットアップアクティビティであり、「activity_setup.xml」がそのレイアウトであり、「myprefs.xml」がプリファレンスレイアウトが保存されているファイルである場合、
次のように、リストの下の「activity_setup.xml」にボタンを配置する必要があります。TableRowで最も望ましい方法です。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/llprefs">
<ListView
android:id="@+id/android:list"
android:tag="lvprefs"
android:layout_width="match_parent"
android:layout_height="0.0dp"
android:layout_weight="1" >
</ListView>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
>
<Button
android:id="@+id/btRegister"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/IdonothaveA"
android:onClick="onClick"
/>
<Button
android:id="@+id/btForgot"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/Iforgot"
android:onClick="onClick" />
<!--
<Button
android:id="@+id/btContact"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/Contact"
android:onClick="onClick" />
-->
</TableRow>