-1
I am developing an application where this one has an Activity where it generates a Listview of Orders, and within the Adapter of this list of orders, I have another Listview that are the items, ie I have a Listview within another Listview.
The problem is that Android does not let put a Listview inside a View that has Scrollview, and by default, a Listview already has Scroll.
To solve this, I found on internet forums a code that would go through the items of my daughter list, take the size of each line and so, adding a total size, but it didn’t work very well in my project, would anyone have another solution for this? thank you.
Code I found on the Internet:
public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null)
return;
int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.UNSPECIFIED);
int totalHeight = 0;
View view = null;
for (int i = 0; i < listAdapter.getCount(); i++) {
view = listAdapter.getView(i, view, listView);
if (i == 0)
view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT));
view.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
totalHeight += view.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
}
What’s going on:
What is going on with this code that you used? Could you send a print of what is happening?
– Boneco Sinforoso
listView.isNestedScrollingEnabled = false
– Eduardo Dornel
@BonecoSinforoso http://uploaddeimagens.com.br/images/002/142/423/full/print_erro.png?1560552933
– Gabriel Mateus
@Eduardodornel did not resolve
– Gabriel Mateus