サウンド設定画面(組み込みの設定アプリで、下の画像を参照)に似たリストビュー画面を作成しようとしています。つまり、一部の行にテキスト+チェックボックスを設定し、他の行にテキスト+「ポップアップ」ボタンを設定します。 、一部の行にはテキストのみを含める必要があります。
これを達成するための最良の方法は何ですか?
Falmarriが指摘しているように、それは単なるではありませListView
んPreferenceActivity
。
を使用できない場合PreferenceActivity
、画面が大きくなった場合にスクロールするさまざまなアイテムのリストを作成する最も簡単な方法は、のScrollView
周りに配置することLinearLayout
です。あなたはここでそれについてもっと読むことができます:http://developer.android.com/reference/android/widget/ScrollView.html
以下は非常に簡単な例です。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="Some text label here"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:text="A button to click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Perhaps an input field here"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="Some more text, and a check box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
現在、このリストにはスクロールするのに十分なアイテムが含まれていませんが、さらに要素を追加し続けると、画面より大きくなるとすぐにスクロールが開始されます。
それはリストビューではありません、それはPreferenceActivity
です。PrefereceActivityクラスを見てください
http://developer.android.com/reference/android/preference/PreferenceActivity.html
リストビューの行ごとに異なるビュー(これは非常に有効です)が本当に必要な場合は、を拡張する独自のクラスを作成する必要がありますBaseAdapter
。このgetView()
メソッドでは、表示するビューを返すだけです。オンラインにはたくさんの例があります。