Android:各行の異なるコンテンツを持つListView画面を作成するにはどうすればよいですか
質問
サウンド設定画面に似たListView画面を作成しようとしています(ビルトイン設定アプリ、下の画像を参照)、つまり、テキスト +チェックボックスを持つ行が必要です。 、一部の行にはテキストのみが必要です。
これを達成するための最良の方法は何ですか?
解決
それはリストビューではありません、それはaです PreferenceActivity
. 。 PepereCeactivityクラスをご覧ください
http://developer.android.com/reference/android/preference/preferenceactivity.html
ListView(非常に有効です)の各行のビューを本当に見たい場合は、拡張する独自のクラスを作成する必要があります。 BaseAdapter
. 。の中に getView()
方法、表示するビューを返してください。オンラインで多くの例があります。
他のヒント
ファルマリが指摘したように、それはそうではありません ListView
しかし、a PreferenceActivity
.
あなたがで作業できない場合 PreferenceActivity
, 、画面が成長した場合にスクロールするさまざまなアイテムのリストを作成する最も簡単な方法は、を配置することです。 ScrollView
aの周り 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>
このリストには、スクロールするのに十分なアイテムが含まれていませんが、さらに要素を追加し続けると、画面よりも大きくなるとすぐにスクロールし始めます。