Frage

I am making an web service based Android application. My problem is child count with expandableListView. I must use 2 different web services. Namely, 1st web service is getting parent informations. I want this, when i clicked parent 2nd web service must start and get child informations. My child counts are flexible. 1st parent have 2 childs, 2nd parent have 5 childs. How can i manage them.

I am using expandablelistviewadapter. This adapter want child counts before using this code "listview.setadapter(adapter)"

So I want to use dynamic child counts. When I clicked parent dialog will show and childs getting from server.

War es hilfreich?

Lösung

I don't get your questin. Writing a custom adapter is the way to go in most cases. So you are on the right way. This adapter should use a datastructure what does what you want.

edit:
this should work right? (Item is my baseclass for dynamic data)

public class MyBaseListAdapter implements ListAdapter {
    List<? extends Item> items;
    @Override
    public int getCount() {
        return items.size();
    }

edit II:
this line may also be improtant for you:

adapter.notifyDataSetChanged();

and you should try to sync or block access while you change the data

Andere Tipps

you should give the child count as what u have for each parent i.e. 0. When parent is clicked, get the children for the clicked parent, update ur data-structure and then call adapter.notifyDataSetChanged();

So I want to use dynamic child counts. When I clicked parent dialog will show and childs getting from server.

There's nothing dynamic about the child counts, you just need to update the adapter when the child data becomes available. As the other answers have pointed out, you need to implement a custom adapter. The basic flow would be:

  • make the first webservice call to retrieve the group data.
  • when that call finishes build an instance of your custom adapter where the child count(getChildrenCount()) is zero(because we don't have any data). Ideally you'll show the user some sort of indicator that data is being retrieved. You spoke about a dialog, I would go(and my example is based on this) with a custom child row which indicates loading(in which case you would return 1 from getChildrenCount()).
  • in the OnGroupClickListener make the call to the webservice to retrieve the data for that particular clicked group. You'll also need to make sure that only the first group click makes the request to fetch data.
  • when the child data for a group becomes available update the adapter(or make it fetch the new data) and call notifyDataSetChanged().

I've made a small sample on how you might approach this(to indicate that the data is being retrieved for a group I make that clicked group to show a loading child row while the data isn't yet available). The code is commented and you can find it here.

MvvmCross version 6.2

_myExpandList = view.FindViewById<ExpandableListView>(Resource.Id.yourExpandedList);
int ExpandViewCount = _myExpandList.Adapter.Count; 

I was looking for this all day and grew increasingly annoyed by all the answers. This seems to be the simplest solution.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top