Main.axml
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
|
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="0"
android:textSize="50sp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txtNumber"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp" />
<Button
android:text="Increment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnIncrement" />
<Button
android:text="Decrement"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnDecrement" />
</LinearLayout>
|
MainActivity.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
|
using Android.App;
using Android.Widget;
using Android.OS;
namespace XamarinTut
{
[Activity(Label = "XamarinTut", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
TextView txtNumber;
int number;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
txtNumber = FindViewById<TextView>(Resource.Id.txtNumber);
FindViewById<Button>(Resource.Id.btnIncrement).Click += (o, e) =>
txtNumber.Text = (++number).ToString();
FindViewById<Button>(Resource.Id.btnDecrement).Click += (o, e) =>
txtNumber.Text = (--number).ToString();
}
}
}
|


0 comments:
Post a Comment
Note: only a member of this blog may post a comment.