0

カスタム タブ ナビゲーターを作成しましたが、カスタム アダプターを受け取る複数の ListView を使用する方法を知る必要があります。

カスタム アダプターを使用する必要があるときは、ListViewwithを作成しid=android:list、クラスを Extends ListActivity に設定しました。でも今思うとそれは仕方ないな…。

4

2 に答える 2

3

1 つのアクティビティで複数の listView を使用するために、ListActivity を拡張する必要はありません。通常の ListView を xml lauyout ファイルに追加し、それらをアクティビティで参照して、必要なアダプターを設定するだけです。

例: xml ファイル

<ListView android:id="@+id/list_view1" android:layout_width="fill_parent"
 android:layout_height="wrap_content">
 </ListView>

<ListView android:id="@+id/list_view2" android:layout_width="fill_parent"
 android:layout_height="wrap_content">
 </ListView>

活動について:

setContentView(R.layout.xmlfile)...

ListView lv1 = (ListView) findViewById(R.id.list_view1);
ListView lv2 = (ListView) findViewById(R.id.list_view2);

lv1.setAdaper(new CustomAdapter1());
lv2.setAdaper(new CustomAdapter2());
于 2012-06-26T10:10:04.383 に答える
1

@ヌノ・ゴンサルベス

XML ファイルの小さな間違い/最適化:

ListViews の場合は、と の両方の属性を として定義しlayout_height、属性を使用してそれらをスケーリングすることをお勧めします。ListView の を に設定することは最適ではなく、エラーやパフォーマンスの問題を引き起こす可能性があります。layout_widthfill_parentlayout_gravitylayout_heightwrap_content

しかし、この場合、あなたのソリューションは機能します:)

例:

<ListView android:id="@+id/list_view1" 
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:layout_gravity="1">
 </ListView>

<ListView android:id="@+id/list_view2" 
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" 
 android:layout_gravity="1">
 </ListView>
于 2012-06-26T11:19:06.677 に答える