我曾經看到過很多關於散列表數據的例子,但我沒有按需要獲取數據。如何獲得散列表數據
這裏是我的代碼:
HashMap<String,ArrayList<String>> citylist = new HashMap<String, ArrayList<String>>();
ArrayList<String> Gujarat = new ArrayList<String>();
Gujarat.add("Surat");
Gujarat.add("Baroda");
Gujarat.add("Ahmedabad");
ArrayList<String> Rajasthan = new ArrayList<String>();
Rajasthan.add("Udaipur");
Rajasthan.add("Jaipur");
ArrayList<String> UP= new ArrayList<String>();
UP.add("Lucknow");
UP.add("Agra");
citylist.put("Gujarat", Gujarat);
citylist.put("UP", UP);
citylist.put("Rajasthan", Rajasthan);
正是在recyclerview如何在BindViewHolder獲取這種類型的數據? 敬酒來了,如:
{Rajasthan=[Udaipur, Jaipur], UP=[Lucknow, Agra], Gujarat=[Surat, Baroda, Ahmedabad]}
我用這種方法來獲得,但錯誤來了:
public void onBindViewHolder(MyViewHolder holder, int position) {
ArrayList<String> lst = citylist.get("" + position);
for (Integer i = 0; i < lst.size(); i++) {
holder.tv.setText(citylist.toString());
Log.e("Hashmap....", ""+holder.tv);
}
輸出應該像古吉拉特邦是國家和蘇拉特巴羅達和艾哈邁達巴德的城市?
是這些靜態或動態 –
動態.. @奇拉格阿羅拉 – Abhi
盡我的代碼,我已經發布 –