原视频地址:http://www.chuanke.com/
Main.axml
android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> android:text="用户名:" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/textView1" android:layout_marginBottom="6.5dp" /> android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/UserName" android:layout_marginRight="0.0dp" /> android:text="密码:" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/textView2" /> android:inputType="textPassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/UserPassword" />
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
EditText editUserName = FindViewById
EditText editUserPassword = FindViewById
//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
android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/spinner1" /> android:text="Text" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/textView1" />
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
//获取消息对象
Spinner _spinner = FindViewById
//声明配置器
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");
};
}
}
}