简体   繁体   中英

ExpandableListView not expanding child nodes

I had an expandable list working in a previous Activity, but I decided to go a different route (Fragments), and wanted to copy the expandable list idea. So I copied/modified the code, but it doesn't seem to be working the way I had hoped.

Truths:

  • I know the data is making its way to the ArrayList, as I'm printing the size() and it's showing the appropriate amount.

  • The list header is appearing, and I can tap it, which flips the carrot(^) upside down.

  • I'm using 3 Fragments, and showing a layout based on which Fragment is selected. I'd like to have one expandable list per fragment, and I think this is doable.

  • class ExpandableListA has worked for me in the past and I haven't changed any of the code, so I would assume it's not the problem.


Selecting a Fragment

@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;
}

Figuring out expandable list

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

}

Error was in my xml layout file. The Fragments were in a ScrollView and after removing that in lue of a LinearLayout, the ExpandableLists worked fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM