forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListViewInPullToRefresh.cs
124 lines (111 loc) · 4.59 KB
/
ListViewInPullToRefresh.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#region Copyright Syncfusion Inc. 2001-2022.
// Copyright Syncfusion Inc. 2001-2022. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// [email protected]. Any infringement will be prosecuted under
// applicable laws.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Graphics;
using Syncfusion.SfPullToRefresh;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
namespace SampleBrowser
{
public class ListViewInPullToRefresh : SamplePage
{
SfPullToRefresh pullToRefresh;
ListView listView;
CustomBaseAdapter adapter;
InboxRepositiory repository;
public ListViewInPullToRefresh()
{
}
public override View GetSampleContent(Context context)
{
pullToRefresh = new SfPullToRefresh(context);
pullToRefresh.TransitionType = TransitionType.Push;
pullToRefresh.Refreshing += Pull_Refreshing;
listView = new ListView(context);
repository = new InboxRepositiory();
adapter = new CustomBaseAdapter((Activity)context, repository.InboxItems);
listView.Adapter = adapter;
pullToRefresh.PullableContent = listView;
return pullToRefresh;
}
private async void Pull_Refreshing(object sender, RefreshingEventArgs e)
{
await Task.Delay(3000);
repository.RefreshItemSource();
adapter.NotifyDataSetChanged();
e.Refreshed = true;
}
public override View GetPropertyWindowLayout(Context context)
{
FrameLayout propertyLayout = new FrameLayout(context);
LinearLayout container = new LinearLayout(context);
container.Orientation = Orientation.Vertical;
container.SetBackgroundColor(Color.White);
container.SetPadding(15, 15, 15, 20);
TextView transitiontype = new TextView(context);
transitiontype.Text = "Tranisition Type";
transitiontype.TextSize = 20;
transitiontype.SetPadding(0, 0, 0, 10);
transitiontype.SetTextColor(Color.Black);
Spinner transitionTypeSpinner = new Spinner(context, SpinnerMode.Dialog);
transitionTypeSpinner.SetMinimumHeight(60);
transitionTypeSpinner.SetBackgroundColor(Color.Gray);
transitionTypeSpinner.DropDownWidth = 600;
transitionTypeSpinner.SetPadding(10, 10, 0, 10);
transitionTypeSpinner.SetGravity(GravityFlags.CenterHorizontal);
container.AddView(transitiontype);
container.AddView(transitionTypeSpinner);
List<String> list = new List<String>();
list.Add("SlideOnTop");
list.Add("Push");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(context, Android.Resource.Layout.SimpleSpinnerItem, list);
dataAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
transitionTypeSpinner.Adapter = dataAdapter;
transitionTypeSpinner.ItemSelected += transitionTypeSpinner_ItemSelected;
if (pullToRefresh.TransitionType == TransitionType.SlideOnTop)
transitionTypeSpinner.SetSelection(0);
else
transitionTypeSpinner.SetSelection(1);
propertyLayout.AddView(container);
return propertyLayout;
}
void transitionTypeSpinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
Spinner spinner = (Spinner)sender;
String selectedItem = spinner.GetItemAtPosition(e.Position).ToString();
if (pullToRefresh != null)
{
if (selectedItem.Equals("SlideOnTop"))
{
pullToRefresh.TransitionType = TransitionType.SlideOnTop;
pullToRefresh.RefreshContentThreshold = 0;
}
else if (selectedItem.Equals("Push"))
{
pullToRefresh.TransitionType = TransitionType.Push;
pullToRefresh.RefreshContentThreshold = 25;
}
}
}
public override void Destroy()
{
pullToRefresh.Refreshing -= Pull_Refreshing;
pullToRefresh.Dispose();
pullToRefresh = null;
}
}
}