[英]ExpandableListView not expanding child nodes
我在上一個活動中有一個可擴展列表,但是我決定走另一條路線(片段),並想復制可擴展列表的想法。 因此,我復制/修改了代碼,但它似乎沒有按照我希望的方式工作。
真相:
我知道數據正在傳遞到ArrayList,因為我正在打印size()並顯示適當的數量。
列表標題出現了,我可以點擊它,將胡蘿卜(^)顛倒過來。
我正在使用3個片段,並顯示基於選擇片段的布局。 我想每個片段有一個可擴展列表,我認為這是可行的。
類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
}
我的xml布局文件中有錯誤。 片段位於ScrollView中,並在LinearLayout的提示下將其刪除后,ExpandableLists可以正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.