-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleMultiplePageActivity.cs
79 lines (64 loc) · 2.78 KB
/
SimpleMultiplePageActivity.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
using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Support.V7.App;
using Android.Widget;
namespace AndroidPageLayout.App {
[Activity(Label = "SimpleMultiplePageActivity", Theme = "@style/AppTheme")]
public class SimpleMultiplePageActivity : AppCompatActivity {
private const string label = nameof(SimpleMultiplePageActivity);
private PageLayout pageLayout;
public static void Start(Activity activity) {
var intent = new Intent(activity, typeof(SimpleMultiplePageActivity));
activity.StartActivity(intent);
}
protected override void OnCreate(Bundle savedInstanceState) {
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.SimpleMultiplePage);
pageLayout = FindViewById<PageLayout>(Resource.Id.PageLayout);
pageLayout.FirstVisiblePageFloatChanged += currentFirstVisiblePageFloatChanged;
setTitle(pageLayout.CurrentFirstVisiblePageFloat);
using (var page = FindViewById<TextView>(Resource.Id.Page1)) {
page.Click += click;
}
using (var page = FindViewById<TextView>(Resource.Id.Page2)) {
page.Click += click;
}
using (var page = FindViewById<TextView>(Resource.Id.Page3)) {
page.Click += click;
}
using (var page = FindViewById<TextView>(Resource.Id.Page4)) {
page.Click += click;
}
}
protected override void OnDestroy() {
using (var page = FindViewById<TextView>(Resource.Id.Page1)) {
page.Click -= click;
}
using (var page = FindViewById<TextView>(Resource.Id.Page2)) {
page.Click -= click;
}
using (var page = FindViewById<TextView>(Resource.Id.Page3)) {
page.Click -= click;
}
using (var page = FindViewById<TextView>(Resource.Id.Page4)) {
page.Click -= click;
}
pageLayout.FirstVisiblePageFloatChanged -= currentFirstVisiblePageFloatChanged;
pageLayout.Dispose();
base.OnDestroy();
}
private void click(object sender, EventArgs args) {
if (sender is TextView textView) {
Toast.MakeText(this, $"Clicked TextView: {textView.Text}", ToastLength.Short).Show();
}
}
private void currentFirstVisiblePageFloatChanged(object sender, FirstVisiblePageFloatChangedEventArgs args) {
setTitle(args.FirstVisiblePageFloat);
}
private void setTitle(float currentFirstVisiblePageFloat) {
SupportActionBar.Title = $"{label} Page:{currentFirstVisiblePageFloat}";
}
}
}