Xamarin.Android之转换,呼叫,查看历史纪录
Xamarin.Android之转换,呼叫,查看历史纪录
功能:能将输入的字母转换成相应的数字。并且能呼叫出去。能查看呼叫的历史纪录。
界面代码如下:
<?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[];
//只有当此Activity继承于ListActivity时,整个视图才是列表,才可以这么写。
this.ListAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleExpandableListItem1, phoneNumbers);
}
}
}
Xamarin.Android之转换,呼叫,查看历史纪录的更多相关文章
- Xamarin.Android开发
使用 Visual Studio 生成第一个 Xamarin.Android 应用程序,并进一步了解使用 Xamarin 进行 Android 应用程序开发的基础知识.在此过程中,会介绍生成和部署 X ...
- Xamarin. Android实现下拉刷新功能
PS:发现文章被其他网站或者博客抓取后发表为原创了,给图片加了个水印 下拉刷新功能在安卓和iOS中非常常见,一般实现这样的功能都是直接使用第三方的库,网上能找到很多这样的开源库.然而在Xamarin. ...
- Xamarin.Android开发实践(十四)
Xamarin.Android之ListView和Adapter 一.前言 如今不管任何应用都能够看到列表的存在,而本章我们将学习如何使用Xamarin去实现它,以及如何使用适配器和自定义适配器(本文 ...
- Xamarin.Android Binding篇
前言 趁着失业了,闲着没事儿学习了下Xamarin.Android binding,在以往的开发中,我相信很多人都遇到过binding的坑,也不例外, 我也踩了很多雷,好在认识了个大佬,指导了很多 ...
- xamarin.android 绑定百度地图SDK遇到的问题
在 xamarin.android 绑定项目中,绑定 百度地图的LBS地图SDK,参考 https://developer.xamarin.com/guides/android/advanced_to ...
- Xamarin android如何反编译apk文件
Xamarin android 如何反编译 apk文件 这里推荐一款XamarinAndroid开发的小游戏,撸棍英雄,游戏很简单,的确的是有点大.等一下我们来翻翻译这个Xamarin Android ...
- Xamarin.Android之ListView和Adapter
一.前言 如今不管任何应用都能够看到列表的存在,而本章我们将学习如何使用Xamarin去实现它,以及如何使用适配器和自定义适配器(本文中的适配器的主要内容就是将原始的数据转换成了能够供列表控件显示的项 ...
- APP并非一个人在战斗,还有API—Xamarin.Android回忆录
前言 一般来说,一个客户端APP并非独立存在的,很多时候需要与服务器交互.大体可分为两方面的数据,常规字符串数据和文件数据,因为这两种数据很可能传输方式不一样,比如字符串之类的数据,使用HTTP协议, ...
- Xamarin.Android之SQLiteOpenHelper
一.前言 在手机中进行网络连接不仅是耗时也是耗电的,而耗电却是致命的.所以我们就需要数据库帮助我们存储离线数据,以便在用户未使用网络的情况下也可以能够使用应用的部分功能,而在需要网络连接的功能上采用提 ...
随机推荐
- ubuntu 12.04 64位设置兼容32位的实现
在ubuntu12.04上,要运行32的程序,需要安装32位的兼容库. 以前在10.04上成功安装过,方法是 sudo apt-get install ia32-libs 但是在12.04上遇到了困难 ...
- 设置Safari浏览器在标签栏上打开新窗口,而不是弹出一个新窗口
打开Safari浏览器的偏好设置,如图: 打开“标签”一项,如上图.在“在标签(而不是窗口)中打开页面:”中设置.
- 如何保护java程序不被反编译
Java是一种 跨平台的.解释型语言 Java 源代码编译中间“字节码”存储于class文件中.Class文件是一种字节码形式的中间代码,该字节码中包括了很多源代码的信息,例如变量名.方法名 等.因此 ...
- android 的通知管理
1在context里定义通知管理器(NotificationManager) NotificationManager notificationManager = (NotificationManage ...
- swiper 页面双向设置
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- PHPExcel读取excel的多个sheet存入数据库
//批量导入文章 excel读取 public function importdata ( $filename, $tmp_name ) { //设置超时时间 set_time_limit(0); $ ...
- HDFS文件读写流程
一.HDFS HDFS全称是Hadoop Distributed System.HDFS是为以流的方式存取大文件而设计的.适用于几百MB,GB以及TB,并写一次读多次的场合.而对于低延时数据访问.大量 ...
- Delphi 2010初体验,是时候抛弃Delphi 7了
Delphi 2010已于近日由Embarcadero公司发布.作者Kim Madsen作为一名资深的Delphi开发者,在他的博客中谈到了Delphi 2010的新性能.它的使用感受以及对Delph ...
- Sql Server数据库之通过SqlBulkCopy快速插入大量数据
废话不多说,直接上代码 /// <summary> /// 海量数据插入方法 /// </summary> /// <param name="connectio ...
- [读书心得]资料分页的优化,以SQL 2012的 OFFSET-FETCH为例
这是我的文章备份,原始出处:[读书心得]资料分页的优化,以SQL 2012的 OFFSET-FETCH为例 http://www.dotblogs.com.tw/mis2000lab/archive/ ...