2015-04-22 46 views
0

嗨,這是我怎麼添加的東西我expandablelist ..ExpandableListView孩子順序是過濾後的不正確

listDataHeader = new ArrayList(Arrays.asList("Afghanistan", 
      "Albania", 
      "Algeria", 
      "Andorra", 
      "Angola", 
      "Anguilla", 
      "Antigua and Barbuda", 
      "Argentina", 
      "Armenia", 
      "Aruba",`........` 

listDataChild =新的HashMap>();

// Adding child data 
List<String> Afghanistan = new ArrayList<String>(); 
Afghanistan.add("Dari"); 
Afghanistan.add("Pashto"); 


List<String> Albania = new ArrayList<String>(); 
Albania.add("Albanian"); 
Albania.add("Greek"); 

List<String> Algeria = new ArrayList<String>(); 
Algeria.add("Arabic"); 
Algeria.add("French"); 
Algeria.add("Berber Dialects"); 

過濾

private class ItemFilter extends Filter { 
     @Override 
     protected FilterResults performFiltering(CharSequence constraint) { 

      String filterString = constraint.toString().toLowerCase(); 

      FilterResults results = new FilterResults(); 

      final List<String> list = originalData; 
      final HashMap<String, List<String>> childList = originalDatachild; 

      int count = list.size(); 
      final ArrayList<String> nlist = new ArrayList<String>(count); 
      final HashMap<String, List<String>> nlistChild= new HashMap<String, List<String>>(); 
      int counterFilter=0; 
      String filterableString ; 

      for (int i = 0; i < count; i++) { 
       filterableString = list.get(i); 
       if (filterableString.toLowerCase().contains(filterString)) { 
        nlist.add(filterableString); 
        /*int ii = i; 
        counterFilter++; 
        while(childList.get(ii)!=null) { 
         nlistChild.put(nlist.get(counterFilter),); 
         ii++; 


        }*/ 
       } 
      } 


      results.values = nlist; 

      results.count = nlist.size(); 

      return results; 
     } 

輸出後是好的......但孩子的項目,不按父項。我不知道該怎麼辦。我想我必須找到一種替代的方式來增加孩子到列表中的以下現有方法..

listDataChild.put(listDataHeader.get(0), Afghanistan);//Header,Child data 
listDataChild.put(listDataHeader.get(1), Albania); 
listDataChild.put(listDataHeader.get(2), Algeria); 
listDataChild.put(listDataHeader.get(3), Andorra); 
listDataChild.put(listDataHeader.get(4), Angola); 
listDataChild.put(listDataHeader.get(5), Anguilla); 

任何幫助嗎?

回答

0

解決:

建立getChild()和getChildrenCount()妥善解決它。

public int getChildrenCount(int groupPosition) { 
    return this.filteredDatachild.get(this.filteredData.get(groupPosition)) 
      .size(); 
} 



public Object getChild(int groupPosition, int childPosititon) { 
     return this.filteredDatachild.get(this.filteredData.get(groupPosition)) 
       .get(childPosititon); 
    } 

和創建新的子名單如下:

for (int i = 0; i < count; i++) { 
      filterableString = list.get(i); 
      if (filterableString.toLowerCase().contains(filterString)) { 
       nlist.add(filterableString); 


       nchildlist.put(nlist.get(ii),originalDatachild.get(nlist.get(ii))); 
       ii++; 
       Log.d("Child Items:", "Child index:" + ii); 
      }