I have a TextView and ListView in my activity.ListView intially set to Visibility = gone I need a functionality like if u
If you want to add ListView on ScrollView and adjust the height of ListView try this code
if (adapter != null) {
int totalHeight = 0;
for (int i = 0; i < adapter.getCount(); i++) {
View listItem = adapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight() + (listItem.getMeasuredHeightAndState()/2);
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (adapter.getCount() - 1));
listView.setLayoutParams(params);
listView.requestLayout();