私はウェブから来るこのタイプの日付を持っています.配列リストで解析した後、これらのデータをすべてリストしています
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 をクリックすると、次のように表示されます。