1

私はウェブから来るこのタイプの日付を持っています.配列リストで解析した後、これらのデータをすべてリストしています

ArrayList<String> countriesid= new ArrayList<String>();
ArrayList<String> countriesName = new ArrayList<String>();
ArrayList<String> cityid= new ArrayList<String>();
ArrayList<String> cityName= new ArrayList<String>();

これが私の実際のデータです。xml形式で、

<Info>
<countryId><![CDATA[1]]></countryId>
<countryName><![CDATA[USA]]></countryName>
<cityId><![CDATA[1]]></cityId>
<cityName><![CDATA[New York]]></cityName>
</Info>
<Info>
<countryId><![CDATA[2]]></countryId>
<countryName><![CDATA[Japan]]></countryName>
<cityId><![CDATA[5]]></cityId>
<cityName><![CDATA[Tokiyo]]></cityName>
</Info>
<Info>
<countryId><![CDATA[6]]></countryId>
<countryName><![CDATA[USA]]></countryName>
<cityId><![CDATA[5]]></cityId>
<cityName><![CDATA[Los Angeles]]></cityName>
</Info>
<Info>
<countryId><![CDATA[19]]></countryId>
<countryName><![CDATA[USA]]></countryName>
<cityId><![CDATA[15]]></cityId>
<cityName><![CDATA[San Diego]]></cityName>
</Info>
<Info>
<countryId><![CDATA[3]]></countryId>
<countryName><![CDATA[Spain]]></countryName>
<cityId><![CDATA[4]]></cityId>
<cityName><![CDATA[Barcelona]]></cityName>
</Data>

注:編集され 、私はすでに次のようなモデルクラスを持っています:

 public class FullInfo{

      public String countryName;
      public String cityName;
      public int countryId;
      public int cityId;
}

最初のステップで、リスト内の繰り返される (重複する) 国名をすべて削除し、次の図のように表示 します。

重複した名前を削除するには

ArrayList<String> RemoveSameCountry= new ArrayList<String>();// fro temp arraylist



 Set set = new HashSet();
    List newList = new ArrayList();
    for (Iterator iter = countriesName.iterator(); 
    iter.hasNext();) {
    Object element = iter.next();
    if (set.add(element))
    newList.add(element);
    }
    RemoveSameCountry.clear();
    RemoveSameCountry.addAll(newList);

それは正常に動作します

ここに画像の説明を入力

リストに表示した後、USA をクリックする必要があります。次に、都市をリストに表示する必要があります。次のようにします。

 If i click USA, How to display list of Cities of USA, I have not idea.

ここに画像の説明を入力

最後に、1 つの都市をクリックすると、その都市の詳細が表示されます。new york をクリックすると、次のように表示されます。 ここに画像の説明を入力

マイ コード: http://pastie.org/pastes/8026498/text

4

1 に答える 1

2

情報クラスを作成する

public class CityInfo {

  public String countryName;
  public String cityName;
  public int countryId;
  public int cityId;
}

そして維持するHashMap<String, List<CityInfo>>

文字列 ( のキーHashMap) を にすることができますcountryName。あなたの最初はのListViewで満たすことができます。keySetHashMap

City ListView に String オブジェクトのデータセットがあるとします。行をクリックすると、onListItemClick が起動されます。

protected void onListItemClick(ListView l, View v, int position, long id) {
     MyAdapter myAdapter = (MyAdapter)l.getAdapter();
     String key = myAdapter.getItem(position);
     List<City> cities = hashMapInstance.get(key);
}
于 2013-06-08T13:21:58.667 に答える