1.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"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:text="请输入电话号码:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Tag" />
<EditText
android:text="13002929017"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/PhoneNumberText" />
<Button
android:text="转化"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/TranslateButton" />
<Button
android:text="呼叫"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/CallButton" />
<Button
android:text="@string/callHistory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/CallHistoryButton"
android:enabled="false" />
</LinearLayout>

2.MainActivity.cs

 using System;
using System.Collections.Generic;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS; namespace Phoneword_Droid
{
[Activity(Label = "Phoneword_Droid", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
int count = ;
static readonly List<string> phoneNumbers = new List<string>(); protected override void OnCreate(Bundle bundle)
{
//button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); }; base.OnCreate(bundle);
SetContentView(Resource.Layout.Main); EditText phoneNumberText = FindViewById<EditText>(Resource.Id.PhoneNumberText);
Button translateButton = FindViewById<Button>(Resource.Id.TranslateButton);
Button callButton = FindViewById<Button>(Resource.Id.CallButton);
Button callHistoryButton = FindViewById<Button>(Resource.Id.CallHistoryButton); callButton.Enabled = false; #region//转化拨号
string translatedNumber = string.Empty;
translateButton.Click += (object sender, EventArgs e) =>
{
translatedNumber = PhoneTranslator.ToNumber(phoneNumberText.Text);
if (String.IsNullOrWhiteSpace(translatedNumber))
{
callButton.Text = "Call";
callButton.Enabled = false;
}
else
{
callButton.Text = "Call" + translatedNumber;
callButton.Enabled = true;
}
};
#endregion #region//拨打电话
callButton.Click += (s, e) =>
{
//对话框
var callDialog = new AlertDialog.Builder(this); //对话框内容
callDialog.SetMessage("Call" + translatedNumber + "?"); //拨打按钮
callDialog.SetNeutralButton("Call", delegate
{
////使用意图拨打电话
//var callIntent = new Intent(Intent.ActionCall); ////将需要拨打的电话设置为意图的参数
//callIntent.SetData(Android.Net.Uri.Parse("tel:" + translatedNumber)); //StartActivity(callIntent); //将电话加入到历史记录列表中
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); }); //取消按钮
callDialog.SetNegativeButton("Cancel", delegate { }); //显示对话框
callDialog.Show();
};
#endregion #region//通话记录
callHistoryButton.Click += (e, t) =>
{
//指定意图需要打开的活动
var intent = new Intent(this, typeof(CallHistoryActivity));
//设置意图传递的参数
intent.PutStringArrayListExtra("phone_numbers", phoneNumbers);
StartActivity(intent);
};
#endregion }
}
}

3.PhoneTranslator.cs

 using System;
using System.Collections.Generic;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS; namespace Phoneword_Droid
{
[Activity(Label = "Phoneword_Droid", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
int count = ;
static readonly List<string> phoneNumbers = new List<string>(); protected override void OnCreate(Bundle bundle)
{
//button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); }; base.OnCreate(bundle);
SetContentView(Resource.Layout.Main); EditText phoneNumberText = FindViewById<EditText>(Resource.Id.PhoneNumberText);
Button translateButton = FindViewById<Button>(Resource.Id.TranslateButton);
Button callButton = FindViewById<Button>(Resource.Id.CallButton);
Button callHistoryButton = FindViewById<Button>(Resource.Id.CallHistoryButton); callButton.Enabled = false; #region//转化拨号
string translatedNumber = string.Empty;
translateButton.Click += (object sender, EventArgs e) =>
{
translatedNumber = PhoneTranslator.ToNumber(phoneNumberText.Text);
if (String.IsNullOrWhiteSpace(translatedNumber))
{
callButton.Text = "Call";
callButton.Enabled = false;
}
else
{
callButton.Text = "Call" + translatedNumber;
callButton.Enabled = true;
}
};
#endregion #region//拨打电话
callButton.Click += (s, e) =>
{
//对话框
var callDialog = new AlertDialog.Builder(this); //对话框内容
callDialog.SetMessage("Call" + translatedNumber + "?"); //拨打按钮
callDialog.SetNeutralButton("Call", delegate
{
////使用意图拨打电话
//var callIntent = new Intent(Intent.ActionCall); ////将需要拨打的电话设置为意图的参数
//callIntent.SetData(Android.Net.Uri.Parse("tel:" + translatedNumber)); //StartActivity(callIntent); //将电话加入到历史记录列表中
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); }); //取消按钮
callDialog.SetNegativeButton("Cancel", delegate { }); //显示对话框
callDialog.Show();
};
#endregion #region//通话记录
callHistoryButton.Click += (e, t) =>
{
//指定意图需要打开的活动
var intent = new Intent(this, typeof(CallHistoryActivity));
//设置意图传递的参数
intent.PutStringArrayListExtra("phone_numbers", phoneNumbers);
StartActivity(intent);
};
#endregion }
}
}

4.CallHistoryActivity.cs

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 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的第二个参数,其实就是指定列表中每个项的视图,后面我们会通过自定义的方式控制列表的项 }
}
}

模拟器

运行效果

Xamarin.Android 入门实例(3)之呼叫电话号码的更多相关文章

  1. Xamarin.Android 入门实例(4)之实现对 SQLLite 进行添加/修改/删除/查询操作

    1.Main.axml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns: ...

  2. Xamarin.Android 入门实例(2)之实现WCF 寄宿于IIS 的Web服务提供

    1.WCF 契约 ICalculator.cs using System.ServiceModel; namespace Contracts { [ServiceContract] public in ...

  3. Xamarin.Android 入门实例(1)之获取与解析JSON

    1.Main.axml 视图界面 2.视图代码 <?xml version="1.0" encoding="utf-8"?> <LinearL ...

  4. 【转】Xamarin.Android 入门之:Xamarin+vs2015 环境搭建

    Xamarin.Android 入门之:Xamarin+vs2015 环境搭建   一.前言 此篇博客主要写了如何使用搭建xamarin开发的环境,防止我自己万一哪天电脑重装系统了,可以直接看这篇博客 ...

  5. Xamarin.Android 入门之:Android API版本设置

    一.引言 Xamarin.Android有几个Android API级别设置,确定多个版本的Android应用程序的兼容性.本博客解释了这些设置意味着什么,如何配置它们,以及它们在运行时对您的应用程序 ...

  6. VS/Xamarin Android入门一

    一.安装和配置(以Visual Studio Pro 2015为例) Visual Studio2015直接提供了这个插件的选择项,稍微提示一下,如果要安装的话,最好准备好十个小时的打算,而且是网速不 ...

  7. Xamarin.Android 入门之:Bind java的jar文件+Android显示gif图片

    一.引言 在xamarin开发的时候,有时我们想要做一个功能,但是这个功能已经有人用java写好了,并且打包成了jar文件.那么我们可以直接把对方的jar文件拿过来用而不是重新用c#写代码. 关于bi ...

  8. Xamarin.Android 入门之:Listview和adapter

    一.引言 不管开发什么软件,列表的使用是必不可少的,而本章我们将学习如何使用Xamarin去实现它,以及如何使用自定义适配器.关于xamarin中listview的基础和适配器可以查看官网https: ...

  9. Xamarin.Android 入门之:Android的生命周期

    一.前言 活动是Android应用程序的基本构建块,他们可以在许多不同的状态存在.当你把一个Android程序置于后台,过一段时间再打开发现之前的数据还存在. 二.活动状态 下面的图表说明了一个活动可 ...

随机推荐

  1. 【Matlab编程】Matlab让电脑失而复得

    在学校常常有同学电脑失窃,大抵都是粗细大意.据说iPhone手机失窃后能够获取小偷的照片,从而将照片找到.如今用matlab写一个程序使得当小偷使用电脑上网时,电脑自己主动将电脑前面的人的照片发到你指 ...

  2. 怎样在Ubuntu上安装最新版本号的Node.js

    怎样在Ubuntu上安装最新版本号的Node.js 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs Node.js是一个软件平台,通经常使用于构建大规模的 ...

  3. Android开发周报:Flyme OS开源、经典开源项目解析

    Android开发周报:Flyme OS开源.经典开源项目解析 新闻 <魅族Flyme OS源码上线Github> :近日魅族正式发布了MX5,并且在发布会上,魅族还宣布Flyme OS开 ...

  4. jQuery EasyUI API 中文文档 - 布局(Layout)

    <html> <head> <script src="jquery-easyui/jquery.min.js"></script> ...

  5. hdu4280(最大流)

    传送门:Island Transport 题意:有N个岛屿 M条无向路 每个路有一最大允许的客流量,求从最西的那个岛屿最多能运用多少乘客到最东的那个岛屿. 分析:无向图正反都加弧,权值一样,这题点多, ...

  6. 【Qt for Android】OpenGL ES 绘制彩色立方体

    Qt 内置对OpenGL ES的支持.选用Qt进行OpenGL ES的开发是很方便的,很多辅助类都已经具备.从Qt 5.0開始添加了一个QWindow类,该类既能够使用OpenGL绘制3D图形,也能够 ...

  7. 30岁生日,媳妇赏的,U-BOAT手表一枚-数字尾巴

    http://bbs.dgtle.com/thread-139611-1-1.html

  8. MFC中模态对话框和非模态对话框的差别

    在MFC中有模态对话框和非模态对话框,那这两种有什么差别呢. 又都是用于什么场合呢. 首先,要弄清楚2种对话框是怎样创建的. 然后要弄清楚2种对话框有什么差别,可能从表面上看,模态会堵塞主对话框.可原 ...

  9. 怎样将android studio项目导入eclipse

    如今,越来越多的开源项目都是用android studio来开发的,所以源码都与eclipse有所不同. 以下是将android studio项目导入eclipse的一般步骤: 1. 先解压项目: 2 ...

  10. Context Switch and System Call

    How many Context Switches is “normal”? This depends very much on the type of application you run. If ...