In this case, your ListView is not actually needed. . You can also iterate over adapter elements and simply add them to the vertical LinearLayout inside your ScrollView.
If you do not want to change a lot of code:
Replace ListView.setAdapter with
LinearLayout ll; //this should be the vertical LinearLayout that you substituted the listview with for(int i=0;i<adapter.getCount();i++) { View v = adapter.getView(position, null, null); ll.addView(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); }
If you already use the OnItemClickListener add-on after View v = adapter.getView(position, null, null); next
final int position = i; v.setOnClickListener(new OnClickListener() { public onClick(View v) { yourOnItemClickListener.onItemClick(null, v, position, 0); } });
In this case, you do not need to worry about any errors in height.
source share