Reputation: 79
I am newbie in xamarin, i am trying to bind dynamic data (consuming from Web Api) to listview. but have no idea how to bind data i have made web api for getting data from database
public List<ProductMaster> GetAllProductOfRestaurent(int id)
{
return entity.ProductMasters.Where(x => x.RestaurentId == id).ToList();
}
now how to consume webapi for list? and bind it to listview? any code sample?
Upvotes: 1
Views: 778
Reputation: 1985
If you are using plain xamarin.android you can bind using Adapters as shown in this article.
Part 2 - Populating a ListView With Data - Xamarin
if you want to use a popular MVVM you need to use third party library like MVVMCross. In MVVMCross you will have MVXListView which can be binded to the Collection of Objects, as below
<Mvx.MvxListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:id="@+id/mlvMantraas"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:divider="@color/primary"
android:dividerHeight="1dp"
android:layout_height="match_parent"
local:MvxBind="ItemsSource Mantraas;ItemClick MantraSelectedCommand"
local:MvxItemTemplate="@layout/mantraitem" >
</Mvx.MvxListView>
Upvotes: 1