0

私はAndroidプログラミングに不慣れで、助けが必要です。私は次のコードを持っています:

Object[] list_cities = parsedData.getCityname().toArray();
            Object[] list_countries = parsedData.getCountryname().toArray();

            // Display the available locations
            list_search.setAdapter(new ArrayAdapter<Object>(this, android.R.layout.simple_list_item_2, android.R.id.text1, list_cities));
            list_search.setAdapter(new ArrayAdapter<Object>(this, android.R.layout.simple_list_item_2, android.R.id.text2, list_countries));

リスト(都市と国)のエントリごとに2行を表示したいのですが、うまくいきません。上記のコードでは、国のみが表示され、都市は表示されません。すべてのデータを表示できるように、両方のアダプターをlist_searchに追加する方法はありますか?

回答ありがとうございます!!

4

2 に答える 2

2
  1. 国名と都市名の文字列をいくつか使用して、カスタムコンテナオブジェクト(CountryCityLocationなど)を作成します。
  2. これらのコンテナの配列を作成し、情報を入力します。
  3. カスタムArrayAdapter(CountryCityAdapterなど)を作成し、配列をカスタムアダプターに適用して、getListView.setAdapterにフィードします。
  4. ArrayAdapterのgetViewメソッドをオーバーライドして、カスタムリスト行ビューのTextViewに名前文字列を適用します。

編集-死んだチュートリアルリンクを削除しました

于 2010-10-13T17:33:31.730 に答える
1

You can bind only one adapter to ListView. If you want to combine adapters you need to implement custom adapter. For example you can inherit SimpleAdapter, provide two simple adapters in constructor and combine data in in getItem method.

于 2010-10-13T10:04:44.030 に答える