magic00 2020-01-10
可以看到按钮被禁用了:
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); });
今天就到这里……