Search code examples
androidandroid-layoutandroid-linearlayoutandroid-adapterhorizontalscrollview

Dynamical Horizontal View


I'm trying to add views dynamically to a linear layout.

I just need the following

From web service i will get category names and image URL and tried to add all the category to linear layout under horizontal view using addview function but only the last category were displayed.

please see the picture below i need such a layout were marked with red rectangle portion have to load category with image dynamically, that portion should be scroll-able horizontally.

enter image description here


Solution

  • simple create custom horizontal list view .use this to generate list view and use an array adapter to set data

    here is my working example enter link description here

    in you layout xml

    <com.jeekiarn.horizontal_listview.HorizoantalListView
        android:id="@+id/hlvSimpleList"
        android:layout_width="match_parent"
        android:layout_height="50dp" />
    
    
    mHlvSimpleList = (HorizoantalListView) findViewById(R.id.hlvSimpleList);
        CustomArrayAdapter adapter = new CustomArrayAdapter(this, mCustomData);
    
        // Assign adapter to HorizontalListView
        mHlvSimpleList.setAdapter(adapter);
        mHlvSimpleList.setAdapter(adapter);