HorizontalListView In Android? No. Use A HorizontalScrollView

There is no HorizontalListView in Android but I have seen someone made a class for that. Problem is, you cannot add any other View in the XML. It simply will not appear, only the HorizontalListView will be there.

The Android API does have a HorizontalScrollView class and I recommend you use this instead since you can place other widgets in the XML file. This sample shows a number of Button objects inside the scroll view class and I added them programmatically since the code I was working on depended on dynamic data.

You can simply place these same Buttons inside the XML.

The MyActivity class is my class that inherits from Activity and is the parameter that is needed by all views since it requires a Context class. This code adds 10 buttons to the HorizontalScrollView class and sets an OnClickListener to activate any code when you click on any of the buttons.

Related Posts Plugin for WordPress, Blogger...


  1. “Problem is, you cannot add any other View in the XML”

    This is just a made-up problem. Thing is, you use adapters for ListViews, be it horizontal or vertical.
    That’s just how it works.

Leave a Reply

Your email address will not be published. Required fields are marked *