0

I am working on an Android app and have recently been given a task where I need to update an existing ListView, containing search results, to include a horizontally scrollable list of cards at the first position. Each card should be tappable, but I should still be able to vertically scroll through the entire list.

I think I can implement this by just using a HorizontalScrollView as a custom view for the first item in the list. However, is there a way to keep the horizontal list and the existing ListView separate, while maintaining the ability to vertically scroll?

M B
  • 327
  • 1
  • 3
  • 8

3 Answers3

0

I'm not entirely sure what you mean by keeping the horizontal list and ListView separate, but I think you can achieve what you want by adding the HorizontalScrollView as a HeaderView to the ListView, as described here:

https://stackoverflow.com/a/14098678/4166923

Community
  • 1
  • 1
Niraj
  • 5,270
  • 2
  • 13
  • 19
0

What about adding a HeaderView to the ListView?

http://developer.android.com/reference/android/widget/ListView.html#addHeaderView(android.view.View,%20java.lang.Object,%20boolean)

ListView list = (ListView) getView().findViewById(R.id.my_list);
LayoutInflater inflater = getActivity().getLayoutInflater();
ViewGroup header =(ViewGroup)inflater.inflate(R.layout.header, list, false);
HorizontalScrollView sv = (HorizontalScrollView)header.findViewById(R.id.scroll_list);
sv.setAdapter(adapter);
list.addHeaderView(header, null, false);
bkurzius
  • 4,020
  • 2
  • 34
  • 34
0

Please check this Sample Horizontal Listview inside vertical listview in android And by putting the Some Condition you can add Other Card also in the Vertical Listview

Sushil
  • 147
  • 1
  • 9