Callum
Callum

Reputation: 65

Displaying list of data in Xamarin forms

My application retrieves data from a firebase backend. The data is retrieved and put into a list object

list type and its variables

      public class UserLogs
{
    public Guid UserID { get; set; }
    public string logData { get; set; }
    public string sliderValue { get; set; }
    public string logTime { get; set; }

}

}

    List<UserLogs> foundLogs = new List<UserLogs>();

Getting the required data from firebase

    foundLogs = (await firebaseClient
        .Child("UserLogs")
        .OnceAsync<UserLogs>()).Where(a => a.Object.UserID == userID).Select(item => new UserLogs
        {
            UserID = item.Object.UserID,
            logData = item.Object.logData,
            sliderValue = item.Object.sliderValue,
            logTime = item.Object.logTime

           
        }).ToList();

When trying to display this list to a list view it will display as the object name e.g.

Screenshot of how list is displayed

values held by foundlogs after getting data

How do I display the data at each index of the list in a listview? For example if I wanted to display the UserID or logData as seen in the variable watch window, how would I do this?

How I am currently displaying the list

    //list of logs being the name of the list view in the xaml file
    ListOfLogs.ItemsSource = foundLogs;

Thank you in advance

Upvotes: 2

Views: 1815

Answers (1)

Jason
Jason

Reputation: 89082

you have to supply a template to tell the data how to be displayed - this is covered extensively in the docs

<ListView>
  <ListView.ItemTemplate>
    <DataTemplate>
      <TextCell Text="{Binding UserID}" />
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

Upvotes: 2

Related Questions