Prabhat Maurya
Prabhat Maurya

Reputation: 1088

How to display two listview in one xaml file one after other in Xamarin .forms?

I have four different listview which is getting data from four different data source.Each listview, I have created separate which is consuming separate RESTful api.I want to display all the listview in one xaml page one after another like notification in facebook. Link for reference - Android how to display 2 listviews in one activity one after the other. I want to create in Xamarin.forms

Upvotes: 0

Views: 2052

Answers (1)

EvZ
EvZ

Reputation: 12169

Not sure what you need, but seems like you want to display at least 4 different data types in a single ListView. It can be done with DataTemplateSelector.

A DataTemplateSelector can be used to choose a DataTemplate at runtime based on the value of a data-bound property. This enables multiple DataTemplates to be applied to the same type of object in order to customize the appearance of select objects.

Examples and details are available here.

P.S.: Having multiple ListViews on the same page, especially four of them, may indicate a UX smell. But, if you still want to have multiple ListView on the same page, it is doable:

<ContentPage>
   <StackLayout Orientation="Vertical">
      <ListView ItemsSource="{Bindind Source1}" />
      <ListView ItemsSource="{Bindind Source2}" />
      <ListView ItemsSource="{Bindind Source3}" />
      <ListView ItemsSource="{Bindind Source4}" />
   </StackLayout>
</ContentPage>

Upvotes: 2

Related Questions