カスタム タブ ナビゲーターを作成しましたが、カスタム アダプターを受け取る複数の ListView を使用する方法を知る必要があります。
カスタム アダプターを使用する必要があるときは、ListView
withを作成しid=android:list
、クラスを Extends ListActivity に設定しました。でも今思うとそれは仕方ないな…。
カスタム タブ ナビゲーターを作成しましたが、カスタム アダプターを受け取る複数の ListView を使用する方法を知る必要があります。
カスタム アダプターを使用する必要があるときは、ListView
withを作成しid=android:list
、クラスを Extends ListActivity に設定しました。でも今思うとそれは仕方ないな…。
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());
@ヌノ・ゴンサルベス
XML ファイルの小さな間違い/最適化:
ListViews の場合は、と の両方の属性を として定義しlayout_height
、属性を使用してそれらをスケーリングすることをお勧めします。ListView の を に設定することは最適ではなく、エラーやパフォーマンスの問題を引き起こす可能性があります。layout_width
fill_parent
layout_gravity
layout_height
wrap_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>