Button btnOK = FindViewById<Button>(Resource.Id.ok);
btnOK.Click += (sender, e) =>
{
EditText entry = FindViewById<EditText>(Resource.Id.entry);
EditText entry2 = FindViewById<EditText>(Resource.Id.entry2);
AlertDialog.Builder dlg = new AlertDialog.Builder(this);
dlg.SetTitle("提示");
dlg.SetMessage(string.Format("你输入的账号是:{0},密码是:{1}", entry.Text, entry2.Text));
dlg.SetPositiveButton("确定", delegate{ });
dlg.Show();
};
Button delOK = FindViewById<Button>(Resource.Id.del);
delOK.Click += new EventHandler(delOK_Click);
void delOK_Click(object sender, EventArgs e)
{
EditText entry = FindViewById<EditText>(Resource.Id.entry);
EditText entry2 = FindViewById<EditText>(Resource.Id.entry2);
entry.Text = "";
entry2.Text = "";
}
页面:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="账号:" />
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/label" />
<TextView
android:id="@+id/label2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/entry"
android:text="密码:" />
<EditText
android:id="@+id/entry2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/label2"
android:password="true" />
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/entry2"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="OK" />
<Button
android:id="@+id/del"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ok"
android:layout_alignTop="@id/ok"
android:text="Cancel" />
</RelativeLayout>