Compare commits

..

No commits in common. '880ce862be80e30cc188456897e7aedc1257e07e' and '49fc9d531916c5b880ea3258cd65565c35b69b88' have entirely different histories.

  1. 25
      XamarinStudy/XamarinStudy/XamarinStudy/Views/SampleListViewPage.xaml
  2. 44
      XamarinStudy/XamarinStudy/XamarinStudy/Views/SampleListViewPage.xaml.cs

@ -4,31 +4,10 @@
x:Class="XamarinStudy.Views.SampleListViewPage"> x:Class="XamarinStudy.Views.SampleListViewPage">
<ContentPage.Content> <ContentPage.Content>
<StackLayout> <StackLayout>
<SearchBar x:Name="foodSearchBar" Placeholder="원하시는 음식을 입력해 주세요" TextChanged="foodSearchBar_TextChanged"/> <ListView x:Name="mainListView" ItemSelected="mainListView_ItemSelected">
<ListView x:Name="mainListView" ItemSelected="mainListView_ItemSelected" ItemsSource="{Binding .}" Footer="{Binding .}"
IsPullToRefreshEnabled="True" Refreshing="mainListView_Refreshing">
<ListView.Header> <ListView.Header>
<ContentView BackgroundColor="Salmon"> <ContentView BackgroundColor="Salmon">
<Label Text="음식 리스트" HorizontalTextAlignment="Center" FontSize="Large" TextColor="White"/> <Label Text="Food List" HorizontalTextAlignment="Center" FontSize="Large" TextColor="White"/>
</ContentView>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Name}" Detail="{Binding Price}"/>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.FooterTemplate>
<DataTemplate>
<Label Text="{Binding Count, StringFormat='{0}ea'}" HorizontalTextAlignment="Center" FontSize="Medium" TextColor="Navy"/>
</DataTemplate>
</ListView.FooterTemplate>
</ListView>
<ListView x:Name="groupedListView" ItemSelected="mainListView_ItemSelected" ItemsSource="{Binding .}" Footer="{Binding .}"
IsPullToRefreshEnabled="True" Refreshing="mainListView_Refreshing"
IsGroupingEnabled="True" GroupDisplayBinding="{Binding Key}">
<ListView.Header>
<ContentView BackgroundColor="Salmon">
<Label Text="음식 리스트" HorizontalTextAlignment="Center" FontSize="Large" TextColor="White"/>
</ContentView> </ContentView>
</ListView.Header> </ListView.Header>
<ListView.ItemTemplate> <ListView.ItemTemplate>

@ -23,27 +23,14 @@ namespace XamarinStudy.Views
private void InitInstance() private void InitInstance()
{ {
//mainListView.ItemsSource = foods; foods = new List<Food>();
//mainListView.Footer = foods; foods.Add(new Food() { Name = "냉면", Price = 10000, Flavor = "시원함" });
foods = GetFoodList(); foods.Add(new Food() { Name = "모밀", Price = 80000, Flavor = "시원함" });
mainListView.BindingContext = foods; foods.Add(new Food() { Name = "국수", Price = 5000, Flavor = "얼큰함" });
groupedListView.BindingContext = foods.OrderBy(f => f.Name).GroupBy(f => f.Flavor).ToList(); foods.Add(new Food() { Name = "쫄면", Price = 5000, Flavor = "매콤함" });
} foods.Add(new Food() { Name = "떡볶이", Price = 3000, Flavor = "매콤함" });
mainListView.ItemsSource = foods;
private List<Food> GetFoodList() mainListView.Footer = foods;
{
List<Food> list = new List<Food>();
list.Add(new Food() { Name = "냉면", Price = 10000, Flavor = "시원함" });
list.Add(new Food() { Name = "모밀", Price = 80000, Flavor = "시원함" });
list.Add(new Food() { Name = "국수", Price = 5000, Flavor = "얼큰함" });
list.Add(new Food() { Name = "쫄면", Price = 5000, Flavor = "매콤함" });
list.Add(new Food() { Name = "떡볶이", Price = 3000, Flavor = "매콤함" });
list.Add(new Food() { Name = "라면", Price = 3000, Flavor = "매콤함" });
list.Add(new Food() { Name = "짜장면", Price = 3000, Flavor = "달콤함" });
list.Add(new Food() { Name = "떡라면", Price = 5000, Flavor = "매콤함" });
list.Add(new Food() { Name = "짜장떡볶이", Price = 3000, Flavor = "달콤함" });
return list;
} }
private void mainListView_ItemSelected(object sender, SelectedItemChangedEventArgs e) private void mainListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
@ -55,20 +42,5 @@ namespace XamarinStudy.Views
DisplayAlert("맛", $"선택한 음식의 맛은 {selected.Flavor} 입니다.", "확인"); DisplayAlert("맛", $"선택한 음식의 맛은 {selected.Flavor} 입니다.", "확인");
mainListView.SelectedItem = null; mainListView.SelectedItem = null;
} }
private void foodSearchBar_TextChanged(object sender, TextChangedEventArgs e)
{
mainListView.BindingContext =
foods.Where(food => food.Name.ToLower().Contains(e.NewTextValue.Replace(" ", "").ToLower())).ToList();
}
private void mainListView_Refreshing(object sender, EventArgs e)
{
foodSearchBar.Text = "";
mainListView.BindingContext = GetFoodList();
DisplayAlert("상태", "음식 리스트를 다시 불러왔습니다.", "확인");
mainListView.EndRefresh();
}
} }
} }
Loading…
Cancel
Save