2

I am currently making app that is using ExpandableListView with cursors provided by CursorTreeAdapter. In my DB I have countries and cities of these countries.

Now I want to implement SearchView thanks to which I will be able to search a specific city. The tricky thing is that when I search I want to display only groups(countries) where relevant city is. I don't want to display empty groups.

For now I have Loader of countries in my main Activity and from there the resulting data is inserted inside my CursorTreeAdapter implementation inside which I am loading cities. Currently I only found only this blog with search in ExpandlableListView, but there isn't implementing any mechanism hiding empty groups.

And that is how my tables look like

Countries table
|ID|Name

City table
|ID|countryID|Name

Does anyone has any idea how it can be achieved?

nurealam11
  • 537
  • 4
  • 16
sebap123
  • 2,541
  • 6
  • 45
  • 81

1 Answers1

1

A simple solution is act at the base..

you might get from db return only those groups with a associated cities, with a join clause:

select co.* 
from Countries co 
inner join City c on (co.ID = c.countryID)

but if you do not sound like a good idea..

another solution is check the row's visibility into the method getGroupView of the adapter MyListAdapter (I'm referring to the blog of example)

@Override
public View getGroupView(int groupPosition, boolean isLastChild, View view, ViewGroup parent) {
   ...
   view.setVisibility((continent.getCountryList().size() == 0) ? View.GONE : View.VISIBLE); 
   ...
   return view;
}

else...

read a similar post:

ExpandableListView is showing indicator for groups with no child

in bindGroupView check if there are child elements and saves the information on the tag of the object view, then newChildView take on the tag, get the visibility and make the view visible or invisible (as I said before)

Community
  • 1
  • 1
  • The first idea I don't think will work, because you are trying to work with two totaly different classes and I don't think that cild cursor can send some info to parent (group) cursor – sebap123 May 27 '14 at 13:35
  • read a similar post: http://stackoverflow.com/questions/11303314/expandablelistview-is-showing-indicator-for-groups-with-no-child – Massimiliano D'Amico May 27 '14 at 14:11