protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Submit Button btnSubmit = FindViewById<Button>(Resource.Id.btnSubmit); btnSubmit.Click += delegate { // Someting event }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Submit Button btnSubmit = FindViewById<Button>(Resource.Id.btnSubmit); btnSubmit.Click += (object sender, EventArgs e) => { btnSubmitClick(sender, e); }; } private void btnSubmitClick(object sender, EventArgs e) { // Someting event }
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/editText1" />
<Button android:text="Button" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/button1" />
<TextView android:text="Medium Text" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/textView1" />
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/txtName" /> <Button android:text="Submit" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/btnSubmit" /> <TextView android:text="Result" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/lblResult" /> </LinearLayout>
using System; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS; namespace myFirstApps { [Activity(Label = "myFirstApps", MainLauncher = true, Icon = "@drawable/icon")] public class MainActivity : Activity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Submit Button btnSubmit = FindViewById<Button>(Resource.Id.btnSubmit); btnSubmit.Click += (object sender, EventArgs e) => { btnSubmitClick(sender, e); }; } private void btnSubmitClick(object sender, EventArgs e) { // Input EditText txtName = FindViewById<EditText>(Resource.Id.txtName); // Result TextView lblResult = FindViewById<TextView>(Resource.Id.lblResult); lblResult.Text = string.Format("Sawatdee Khun : {0} ", txtName.Text); } } }
// Submit Button btnSubmit = FindViewById<Button>(Resource.Id.btnSubmit); btnSubmit.Click += delegate { // Input EditText txtName = FindViewById<EditText>(Resource.Id.txtName); // Result TextView lblResult = FindViewById<TextView>(Resource.Id.lblResult); lblResult.Text = string.Format("Sawatdee Khun : {0} ", txtName.Text); };
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท