Adding Column Headers to a ListView in Android

I have a ListView in android and i want to add headers to it's columns which are:
ProductID Product Quantity Price
But i cannot find out how to do that in Android.



  • CortezCortez USMember ✭✭✭

    TableLayout is better for showing datas in a grid. You can also configure a listview to do that. In the main view add a new LinearLayout at the beginning with horizontal alignment. Here you can define your column headers in TextViews (ProductID, Product, Quantity, Price), then add your listview. Because of the default LinearLayout's vertical aligment it will be under your first LinearLayout (header row). Now create an adapter and copy your header's axml. Exchange your textviews with edittext or anything you want. After that you can handle and show your collection form the adapter. Add or delete rows, set Price for each row, etc. This is a very basic implementation.

  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭

    Hello @OsayedZaheda
    you need to add an xml file to your project with the header as mentionned cortez with a tableLayout
    and on your listview add the header ...

    ListView lv = FindViewById<ListView>(Resource.Id.listView); ViewGroup headerView = (ViewGroup)LayoutInflater.Inflate(Resource.Layout.header, lv, false); lv.AddHeaderView(headerView);
    a good sample but in java , i've just to test it in xamarin android and not enough difficult to translate

Sign In or Register to comment.