Listview 5 "items" horizontal with a vertical scroll Android -
i know how make listview
5 items per row horizontal vertical scroll
you need create custom row, have 60 rows.
lets asume have
arraylist<string> cars
with cars data.
@override public view getview(int position, view convertview, viewgroup parent) { //determine first car int firstcarposition = position*5; carlistitem item = new carlistitem(context); item.fillitem(firstcarposition); return item; }
then create class one
public class carlistitem extends linearlayout { public singlerowlistitem(context context) { super(context); layoutinflater inflater = (layoutinflater)getcontext().getsystemservice(context.layout_inflater_service); inflater.inflate(r.layout.list_item_cars_row, this, true); } public void fillitem(int firstposition) { textview car1 = (textview)findviewbyid(r.id.car1); textview car2 = (textview)findviewbyid(r.id.car2); textview car3 = (textview)findviewbyid(r.id.car3); textview car4 = (textview)findviewbyid(r.id.car4); textview car5 = (textview)findviewbyid(r.id.car5); car1.settext(cars.get(firstposition); car2.settext(cars.get(firstposition+1); car3.settext(cars.get(firstposition+2); car4.settext(cars.get(firstposition+3); car5.settext(cars.get(firstposition+4); } }
finally, create xml called list_item_car_row:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="60dp" android:background="@drawable/standard_background" android:orientation="horizontal" > <textview android:id="@+id/car1" android:layout_height="wrap_content" android:layout_weight="wrap_content"/> <textview android:id="@+id/car2" android:layout_height="wrap_content" android:layout_weight="wrap_content"/> <textview android:id="@+id/car3" android:layout_height="wrap_content" android:layout_weight="wrap_content"/> <textview android:id="@+id/car4" android:layout_height="wrap_content" android:layout_weight="wrap_content"/> <textview android:id="@+id/car5" android:layout_height="wrap_content" android:layout_weight="wrap_content"/> </linearlayout>
that called component, not system default item. component based on 6 textviews. edit xml, add more data , make cool 1 :)
Comments
Post a Comment