标签:history protect gate android开发 put sla label 提前 val





可以看到按钮被禁用了:
![]()

namespace Phoneword_Droid
{
[Activity(Label = "@string/callHistory")]
public class CallHistoryActivity : ListActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
//从意图中获取传递过来的参数
var phoneNumbers = Intent.Extras.GetStringArrayList("phone_numbers") ?? new string[0];
//将字符串数组显示到列表控件中(因为继承的是ListActivity所以整个视图就是一个列表)
this.ListAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, phoneNumbers);
//关于ArrayAdapter的第二个参数,其实就是指定列表中每个项的视图,后面我们会通过自定义的方式控制列表的项
}
}
}
[Activity(Label = "Phoneword_Droid", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
static readonly List<string> phoneNumbers = new List<string>();
Button callHistoryButton = FindViewById<Button>(Resource.Id.CallHistoryButton);
callHistoryButton.Click += (e, t) =>
{
//指定意图需要打开的活动
var intent = new Intent(this, typeof(CallHistoryActivity));
//设置意图传递的参数
intent.PutStringArrayListExtra("phone_numbers", phoneNumbers);
StartActivity(intent);
};
//拨打按钮
callDialog.SetNeutralButton("Call", delegate
{
//将电话加入到历史记录列表中
phoneNumbers.Add(translatedNumber);
//如果callHistoryButton的定义在这段代码后面将会出错,所以我们这个时候需要将
//Button callHistoryButton = FindViewById<Button>(Resource.Id.CallHistoryButton); 代码提前
callHistoryButton.Enabled = true;
//使用意图拨打电话
var callIntent = new Intent(Intent.ActionCall);
//将需要拨打的电话设置为意图的参数
callIntent.SetData(Android.Net.Uri.Parse("tel:" + translatedNumber));
StartActivity(callIntent);
});


今天就到这里……
VS/Xamarin Android开发Follow Me(二)
标签:history protect gate android开发 put sla label 提前 val
原文地址:https://www.cnblogs.com/xtxk110/p/12174613.html