I have 2 list views in a fragment stacked vertically. The top list has a fixed number of rows(it doesn't change). The second list is populated dynamically. My question is I want the first list to always be visible and the second to be able to scroll if it has many rows. I should say when the second list is scrolling, it SHOULD NOT scroll the first. It should only scroll its contents.
Asked
Active
Viewed 77 times
0
-
Did you try adding a `ScrollView` container around your second list? – not_again_stackoverflow Aug 03 '16 at 10:24
-
@not_again_stackoverflow ListView doesn't work inside a ScrollView. WRAP_CONTENT shows only first item, don't do that. – Eugen Pechanec Aug 03 '16 at 10:59
2 Answers
0
Apply this to the list view you don't want to scroll:
listView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// If the user wants to scroll, override the default event
if (event.getAction() == MotionEvent.ACTION_MOVE) {
return true; // So the system doesn't handle the event
}
return false;
}
});
The second list view should still be able to scroll.
Original Answer in this thread

Community
- 1
- 1

Simon Schiller
- 644
- 1
- 8
- 23
-
The second list view isn't scrolling. And also the first list view(the one that should not scroll) is behaving weird, it is selecting list items(rows) that haven't been selected, if I attempt to scroll across it, it interprets that as list item selection. – fuadj Aug 03 '16 at 12:55
-
Maybe it would be easier for you to replace the first list view with a linear layout, since it should not scroll – Simon Schiller Aug 03 '16 at 13:00
-
Yes, I think that is the proper method. But there are many rows in the first list(5 rows) that would be easier to populate by a list adapter than to manually create them in a vertical linear layout – fuadj Aug 03 '16 at 13:01
0
Add the first list contents in some other layout (not ScrollView,ListView) ex.LinearLayout, So you can have only one scrollable list item that is the second one

Anbarasu Chinna
- 975
- 9
- 28