1

我有一個可擴展的列表工作在以前的活動,但我決定去一個不同的路線(碎片),並希望複製可擴展列表的想法。所以我複製/修改了代碼,但它似乎沒有按照我希望的方式工作。ExpandableListView不擴展子節點

真相:

  • 我知道數據是做它的方式到ArrayList,因爲我打印 大小()和它的顯示相應的金額。

  • 列表標題出現,我可以點擊它,它翻轉胡蘿蔔(^)顛倒。

  • 我使用3片段,並顯示基於哪個片段被選中的佈局。我想每個片段都有一個可擴展列表,我認爲這是可行的。

  • class ExpandableListA在過去爲我工作過,而且我沒有更改任何代碼,所以我會認爲這不是問題。


選擇片段

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 

    ViewGroup rootView; 
    TextView tv; 

    switch(getPageNumber()){ 
     default: 
     case 0: 
      rootView = (ViewGroup) inflater.inflate(R.layout.fragment_today, container, false); 
      tv = (TextView)rootView.findViewById(R.id.today_frag_tv); 
      tv.append(todays_data[0]); 
      expandable_list(todays_data, rootView); 
      break; 
     case 1: 
      rootView = (ViewGroup) inflater.inflate(R.layout.fragment_specials, container, false); 
      tv = (TextView)rootView.findViewById(R.id.specials_frag_tv); 
      // will figure this out 
      break; 
     case 2: 
      rootView = (ViewGroup) inflater.inflate(R.layout.fragment_business, container, false); 
      tv = (TextView)rootView.findViewById(R.id.biz_frag_tv); 
      // will figure this out     
      break; 
    } 

    return rootView; 
} 

搞清楚擴展列表

public void expandable_list(final String biz_data[], ViewGroup rootView){ 

    // get the listview 
    expListView = (ExpandableListView) rootView.findViewById(R.id.lvExpToday); 

    // preparing list data 
    prepareListData(biz_data); 

    // 
    listAdapter = new ExpandableListA(getActivity(), listDataHeader, listDataChild); 

    // setting list adapter 
    expListView.setAdapter(listAdapter); 

} 

private void prepareListData(String biz_data[]) { 

    listDataHeader = new ArrayList<String>(); 
    listDataChild = new HashMap<String, List<String>>(); 

    // Adding child data 
    listDataHeader.add(biz_data[0]); 

    Log.d("b_d length: ", Integer.toString(biz_data.length)); 

    // Adding child data 
    List<String> mon = new ArrayList<String>(); 

    for (int i = 1; i < biz_data.length;i++) 
     mon.add(biz_data[i]); 

    Log.d("mon length: ", Integer.toString(mon.size())); 

    listDataChild.put(listDataHeader.get(0), mon); // Header, Child data 

} 

回答

0

錯誤是在我的XML佈局文件。碎片在ScrollView中,並在LinearLayout中刪除之後,ExpandableLists正常工作。