android nested listview

Ben picture Ben · Jun 28, 2010 · Viewed 30.4k times · Source

is it possible/advisable to have a nested listview?

i.e. a listView that's contained within a row of another listview?

an example would be where my main list is displaying blog posts, and then in each row, you'd have another list view for the comments for each post (that would be collapsible)

Answer

Paulo Cesar picture Paulo Cesar · May 12, 2011

I had the same problem today, so this is what I did to solve it:

I have a ListView, with a CustomAdapter, and on the getView of the customAdapter, I have something like this:

LinearLayout list = (LinearLayout) myView.findViewById(R.id.list_musics);
list.removeAllViews();

for (Music music : albums.get(position).musics) {
    View line = li.inflate(R.layout.inside_row, null);

    /* nested list's stuff */

    list.addView(line);
}

So, resuming, It's not possible to nest to ListViews, but you can create a list inside a row using LinearLayout and populating it with code.