Xamarin.Android之转换,呼叫,查看历史纪录
2015-05-05 15:02
232 查看
Xamarin.Android之转换,呼叫,查看历史纪录
E文文章。
功能:能将输入的字母转换成相应的数字。并且能呼叫出去。能查看呼叫的历史纪录。
界面代码如下:
主Activity代码。
通话纪录的Activity代码。
E文文章。
功能:能将输入的字母转换成相应的数字。并且能呼叫出去。能查看呼叫的历史纪录。
界面代码如下:
<?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"> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="0712-XAMARIN" android:id="@+id/et" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="转换" android:id="@+id/btnTran" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="呼叫" android:id="@+id/btnCall" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="历史纪录" android:id="@+id/btnCallHistory" /> </LinearLayout>
主Activity代码。
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 App3 { [Activity(Label = "CallActivity", MainLauncher = true, Icon = "@drawable/icon2")] public class CallActivity : Activity { //定义手机集合。 private static readonly List<string> PhoneNumbers = new List<string>(); protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Call); EditText et = FindViewById<EditText>(Resource.Id.et); Button btnTran = FindViewById<Button>(Resource.Id.btnTran); Button btnCall = FindViewById<Button>(Resource.Id.btnCall); btnCall.Enabled = false; Button btnCallHistory = FindViewById<Button>(Resource.Id.btnCallHistory); btnCallHistory.Enabled = false; string translatedNumber = string.Empty; btnTran.Click += (sender, e) => { translatedNumber = PhoneTranslator.ToNumber(et.Text); //将转换的手机号加入到手机集合中。 PhoneNumbers.Add(translatedNumber); btnCallHistory.Enabled = true; if (String.IsNullOrWhiteSpace(translatedNumber)) { btnCall.Text = "呼叫"; btnCall.Enabled = false; } else { btnCall.Text = "呼叫" + translatedNumber; btnCall.Enabled = true; } }; btnCall.Click += (sender, e) => { //对话框 var callDialog = new AlertDialog.Builder(this); callDialog.SetMessage("呼叫" + translatedNumber + "?"); //拨打按钮 callDialog.SetNeutralButton("呼叫", delegate { //使用意图拨打电话 var callIntent = new Intent(Intent.ActionCall); //将需要拨打的电话设置为意图的参数.注意写法 callIntent.SetData(Android.Net.Uri.Parse("tel:" + translatedNumber)); StartActivity(callIntent); }); callDialog.SetNegativeButton("取消", delegate { }); callDialog.Show(); }; btnCallHistory.Click += (sender, e) => { //用意图打开历史纪录的活动 Android.Content.Intent it = new Intent(this, typeof(CallHistoryActiviry)); it.PutStringArrayListExtra("phoneNumbers", PhoneNumbers); StartActivity(it); }; } } }
通话纪录的Activity代码。
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 App3 { [Activity(Label = "CallHistoryActiviry")] public class CallHistoryActiviry : ListActivity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); var phoneNumbers = Intent.Extras.GetStringArrayList("phoneNumbers") ?? new string[0]; //只有当此Activity继承于ListActivity时,整个视图才是列表,才可以这么写。 this.ListAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleExpandableListItem1, phoneNumbers); } } }
相关文章推荐
- Android实现简易计步器功能,隔天步数清零,查看历史运动纪录
- Android实现简易计步器功能,隔天步数清零,查看历史运动纪录
- Android实现简易计步器功能隔天步数清零查看历史运动纪录
- 网站商务通如何导出查看历史聊天纪录
- Android2.2查看svn历史提交记录
- android git查看某个文件的修改历史
- 关于android查看电池历史记录中的电池已使用时间解释
- Android Eclipse之Git插件安装、配置、提交、修改、冲突、查看历史、覆盖。
- android 查看电量情况,手机信息,电池历史记录,使用情况统计 ,wifi 使用情况
- Android Eclipse之Git插件安装、配置、提交、修改、冲突、查看历史、覆盖。
- Xamarin.Android 入门实例(3)之呼叫电话号码
- android搜索功能以及显示历史纪录带清除按钮
- SQL Server2005中查看Schema更改历史纪录
- msn无法查看历史聊天记录解决方法
- 打开别人Xamarin项目找不到android.jar文件
- xamarin.android 资源图片问题
- Android屏幕像素转换
- java android 金额大小写数据的转换
- Android开源项目 分类 便于查看
- Java中byte与16进制字符串的互相转换 分类: Android JAVA 2015-05-26 19:07 25人阅读 评论(0) 收藏