I have a listview with data from a list called actualmeterreading. In each row, there are a label and entry, both display data from the list. User can edit the data displayed in entry. How can I loop through the listview and get the data that user input in the entry?
Code for populating the listview.
list = new ListView
{
ItemsSource = actualmeterreading,
RowHeight = 50,
ItemTemplate = new DataTemplate(() =>
{
printDesc = new Label();
string desc = actualmeterreading[x].MachineMeterReadingList.Meterreadingdescription.Description;
printDesc.Text = desc;
meterreading = new Entry();
string reading = actualmeterreading[x].ActualReading.ToString();
meterreading.Text = reading;
meterreading.FontSize = 14;
x = x + 1;
//nameLabel2.WidthRequest = 300;
//nameLabel2.SetBinding(Entry.TextProperty, "");
// Return an assembled ViewCell.
return new ViewCell
{
View = new StackLayout
{
Padding = new Thickness(0, 5),
Orientation = StackOrientation.Horizontal,
Children =
{
new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Spacing = 0,
Children =
{
printDesc,
meterreading
//nameLabel2
}
}
}
}
};
})
};
Loop through the listview on submit button click.
private void submitbtn_Clicked(object sender, EventArgs e)
{
int x = 0;
foreach (var c in list.ItemsSource)
{
int r = c.?
myactualreading = new actualmeterreading
{
ActualReading = r
};
x = x + 1;
dataservice.UpdateActualReading(myactualreading);
}
}
When I did some search, there was someone who mention to View models and two ways bindings. Does anyone have some solution regarding that one or any other solutions? Thank you