ListView获取多个条目值以进行验证和发送 [英] ListView Get Multiple Entry Values to validate and send
本文介绍了ListView获取多个条目值以进行验证和发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
希望您能在此方面为我提供帮助.
I hope you can help me on this.
我有一个来自API的调查,我想在ListView中显示它们,但是我的问题是,如何通过单击发送"按钮来验证每个条目?
I have a survey from API, I want to display them in a ListView but my issue is, how can I validate each Entry from clicking a Send Button?
我的代码隐藏
public class SurveyList
{
public List<QuestionList> Questions { get; set; }
}
public class QuestionList
{
public string QuestionText { get; set; }
public string QuestionCode { get; set; }
}
public partial class SurveyPage : ContentPage
{
public SurveyPage()
{
InitializeComponent();
var surveyListData = new List<QuestionList>
{
new QuestionList { QuestionText = "Question 1?", QuestionCode = "01" },
new QuestionList { QuestionText = "Question 2?", QuestionCode = "02" }
};
surveyList.ItemsSource = surveyListData;
}
void Handle_Clicked(object sender, System.EventArgs e)
{
// Button Clicked Get Values Here and Do Something
}
}
}
我的XAML
<ListView x:Name="surveyList"
HasUnevenRows="true"
SeparatorVisibility="Default"
BackgroundColor="White">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="10" BackgroundColor="Purple">
<StackLayout Spacing="10" VerticalOptions="Start" HorizontalOptions="FillAndExpand" BackgroundColor="Olive">
<Label Text="{Binding QuestionLabel}" TextColor="Navy"/>
<Picker x:Name="QuestionPicker">
<Picker.Items>
<x:String>Yes</x:String>
<x:String>No</x:String>
</Picker.Items>
</Picker>
</StackLayout>
<StackLayout Spacing="20" VerticalOptions="End" HorizontalOptions="FillAndExpand" BackgroundColor="Maroon">
<Button x:Name="surveyButton"
Text="Enviar"
TextColor="White"
BackgroundColor="{StaticResource dpGreen}"
Clicked="Handle_Clicked"/>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
使用此代码,我正在测试如何从单击的按钮中获取所有值
With this code, I am testing out how to get all values from the clicked button
推荐答案
使用@Andrew所说的Foreach解决问题.
Using a Foreach as @Andrew said, solve the question.
void Handle_Clicked(object sender, System.EventArgs e)
{
foreach(var getValues in survey)
{
getValuesOfPickers.Text = getValues.QuestionCode;
}
}
不确定是否可以完全解决问题,但是正如@Andrew所说,原始问题得到了回答
Not sure if it solve it completely, but as @Andrew said, the original question was answered
这篇关于ListView获取多个条目值以进行验证和发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文