Skip to content Skip to sidebar Skip to footer

How To Set Scrollview In Activity With Multiple Listview(s)?

This is my actual Activity : In this Activity I set All the ListView(s) dynamically and programmatically. As you can see, the problem I have is The 1st ListView takes the place sh

Solution 1:

You should not nest ListViews inside a ScrollView, Android won't know which to scroll. Maybe... you will be able to set programatically the fixed height for each ListView, and then it will work.

What I would recommend is either to use a single ListView, and group in that list all the data, or to use an ExpandableListView.

Solution 2:

Generally its a bad practice to add the ListView inside ScrollView. If you put your ListView or any scrollable View inside theScrollViewit won't work properly because when you touch the screen ,main focus of your touch is on parent view(ScrollView) not the child View (ListView`).

Still if you want to implement it then below is the way you can try out, which is to add the FooterView or HeaderView in your ListView.

Add views that should be above ListView as a header:

addHeaderView(View v);

and that below as a footer:

addFooterView(View v);

Put everything what should be above ListView to Header of ListView and the same with footer to add below.

LayoutInflater inflater = LayoutInflater.from(this);
mTop    = inflater.inflate(R.layout.view_top, null);
mBottom = inflater.inflate(R.layout.view_bottom, null);

list.addHeaderView(mTop);
list.addFooterView(mBottom);
// add header and footer before setting adapter
list.setAdapter(mAdapter);

In result you'll get one scrollable view.

Post a Comment for "How To Set Scrollview In Activity With Multiple Listview(s)?"