原视频地址:http://www.chuanke.com/
Main.axml
<?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">
<TextView
android:text="用户名:"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView1"
android:layout_marginBottom="6.5dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/UserName"
android:layout_marginRight="0.0dp" />
<TextView
android:text="密码:"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView2" />
<EditText
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/UserPassword" />
<Button
android:text="登陆"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnEnter" />
</LinearLayout>
MainActivity
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace App2
{
[Activity(Label = "App2", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
int count = 1;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button>(Resource.Id.btnEnter);
EditText editUserName = FindViewById<EditText>(Resource.Id.UserName);
EditText editUserPassword = FindViewById<EditText>(Resource.Id.UserPassword);
//button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
button.Click += (sender, e) =>
{
if (editUserName.Text == "sa" && editUserPassword.Text == "123")
{
Intent intent = new Intent(this, typeof (Index));
intent.PutExtra("userName", editUserName.Text);
StartActivity(intent);
}
else
{
//提示:登陆失败
Toast.MakeText(this,"登陆失败!",ToastLength.Long).Show();
}
};
}
}
}
Index.axml
<?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">
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinner1" />
<TextView
android:text="Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView1" />
</LinearLayout>
Index
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;
namespace App2
{
[Activity(Label = "Index")]
public class Index : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Index);
// Create your application here
TextView textView = FindViewById<TextView>(Resource.Id.textView1);
//获取消息对象
Spinner _spinner = FindViewById<Spinner>(Resource.Id.spinner1);
//声明配置器
ArrayAdapter arrayAdapter=new ArrayAdapter(this,Android.Resource.Layout.SimpleSpinnerDropDownItem);
arrayAdapter.Add("北京");
arrayAdapter.Add("上海");
arrayAdapter.Add("广州");
arrayAdapter.Add("深圳");
//设置适配器
_spinner.Adapter = arrayAdapter;
_spinner.ItemSelected += (sender, e) =>
{
textView.Text = arrayAdapter.GetItem(e.Position).ToString();
textView.Text = "当前用户是:" + Intent.GetStringExtra("userName");
};
}
}
}