Xamarin.Android之转换,呼叫,查看历史纪录

摘要:
Xamarin。Android转换、调用和查看电子文本文章的历史记录。˃2671314neneneba 2021年2728“33/˃3436主要活动代码。1usingSystem;2usingSystem.Collections.Generic;3usingSystem.Linq;4usingSystem.Text;56usingAndroid.App;7usingAndrio.Content;8usingAndrOS.OS;9usingAndrool.Runtime;10usingAndrro.Views;11usingAndrox.Widget;1213namespaceApp314{15[activity]16 publicclassCallActivity:Activity17{18//定义电话集合。19 privatestaticreationonnlyList<string>PhoneNumbers=newList<string˃();20 protectedoverridevoidOnCreate21{22base.OnCreate;23SetContentView;24EditTextet=FindViewById;25ButtonbtnTran=FindViewById;26ButtonbtnCall=FindViewById{35translatedNumber=PhoneTranslator.ToNumber;36//将转换后的电话号码添加到电话集合中。37PhoneNumbers.Add;38btnCallHistory.Enabled=true;39if40{41btnCall.Text=“Call”;42btnCall.Enabled=false;43}44else45{46btnCall.Dext=“Call”+translatedNumber;47btnCall.Inabled=true;48}49};505152btn呼叫。单击+==˃53{54//Dialog 55 varcallDialog=newAlertDialog.Builder;56callDialog.SetMessage(“Call”+translatedNumber+“?

                                                         Xamarin.Android之转换,呼叫,查看历史纪录

        E文文章。

       功能:能将输入的字母转换成相应的数字。并且能呼叫出去。能查看呼叫的历史纪录。

       界面代码如下:   

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:orientation="vertical"
 4     android:layout_width="fill_parent"
 5     android:layout_height="fill_parent">
 6 
 7   <EditText
 8           android:layout_width="fill_parent"
 9      android:layout_height="wrap_content"
10        android:text="0712-XAMARIN"
11           android:id="@+id/et"
12     />
13 
14   <Button
15              android:layout_width="fill_parent"
16      android:layout_height="wrap_content"
17        android:text="转换"
18           android:id="@+id/btnTran"
19     />
20 
21   <Button
22            android:layout_width="fill_parent"
23        android:layout_height="wrap_content"
24        android:text="呼叫"
25           android:id="@+id/btnCall"
26     />
27 
28   <Button
29             android:layout_width="fill_parent"
30         android:layout_height="wrap_content"
31         android:text="历史纪录"
32            android:id="@+id/btnCallHistory"
33     />
34 
36 </LinearLayout>

     主Activity代码。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 using Android.App;
 7 using Android.Content;
 8 using Android.OS;
 9 using Android.Runtime;
10 using Android.Views;
11 using Android.Widget;
12 
13 namespace App3
14 {
15     [Activity(Label = "CallActivity", MainLauncher = true, Icon = "@drawable/icon2")]
16     public class CallActivity : Activity
17     {
18         //定义手机集合。
19         private static readonly List<string> PhoneNumbers = new List<string>();
20         protected override void OnCreate(Bundle bundle)
21         {
22             base.OnCreate(bundle);
23             SetContentView(Resource.Layout.Call);
24             EditText et = FindViewById<EditText>(Resource.Id.et);
25             Button btnTran = FindViewById<Button>(Resource.Id.btnTran);
26             Button btnCall = FindViewById<Button>(Resource.Id.btnCall);
27             btnCall.Enabled = false;
28             Button btnCallHistory = FindViewById<Button>(Resource.Id.btnCallHistory);
29             btnCallHistory.Enabled = false;
30             string translatedNumber = string.Empty;
31 
32 
33             btnTran.Click += (sender, e) =>
34             {
35                 translatedNumber = PhoneTranslator.ToNumber(et.Text);
36                 //将转换的手机号加入到手机集合中。
37                 PhoneNumbers.Add(translatedNumber);
38                 btnCallHistory.Enabled = true;
39                 if (String.IsNullOrWhiteSpace(translatedNumber))
40                 {
41                     btnCall.Text = "呼叫";
42                     btnCall.Enabled = false;
43                 }
44                 else
45                 {
46                     btnCall.Text = "呼叫" + translatedNumber;
47                     btnCall.Enabled = true;
48                 }
49             };
50 
51 
52             btnCall.Click += (sender, e) =>
53             {
54                 //对话框
55                 var callDialog = new AlertDialog.Builder(this);
56                 callDialog.SetMessage("呼叫" + translatedNumber + "?");
57                 //拨打按钮
58                 callDialog.SetNeutralButton("呼叫", delegate
59                 {
60                     //使用意图拨打电话
61                     var callIntent = new Intent(Intent.ActionCall);
62                     //将需要拨打的电话设置为意图的参数.注意写法
63                     callIntent.SetData(Android.Net.Uri.Parse("tel:" + translatedNumber));
64                     StartActivity(callIntent);
65                 });
66                 callDialog.SetNegativeButton("取消", delegate { });
67                 callDialog.Show();
68             };
69 
70 
71             btnCallHistory.Click += (sender, e) =>
72             {
73                 //用意图打开历史纪录的活动
74                 Android.Content.Intent it = new Intent(this, typeof(CallHistoryActiviry));
75                 it.PutStringArrayListExtra("phoneNumbers", PhoneNumbers);
76                 StartActivity(it);
77             };
78 
79         }
80     }
81 }

    通话纪录的Activity代码。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 using Android.App;
 7 using Android.Content;
 8 using Android.OS;
 9 using Android.Runtime;
10 using Android.Views;
11 using Android.Widget;
12 
13 namespace App3
14 {
15     [Activity(Label = "CallHistoryActiviry")]
16     public class CallHistoryActiviry : ListActivity
17     {
18         protected override void OnCreate(Bundle bundle)
19         {
20             base.OnCreate(bundle);
21             var phoneNumbers = Intent.Extras.GetStringArrayList("phoneNumbers") ?? new string[0];
22             //只有当此Activity继承于ListActivity时,整个视图才是列表,才可以这么写。
23             this.ListAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleExpandableListItem1, phoneNumbers);
24         }
25     }
26 }

       

免责声明:文章转载自《Xamarin.Android之转换,呼叫,查看历史纪录》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Python 持久化管理之 Pickle/ZODB(二)语音合成测试案例下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Android典型界面设计(6)——ActionBar Tab+ViewPager+Fagment实现滑动导航

一、问题描述   在Android典型界面设计一文中,实现典型滑动导航界面,其实使用ActionBar 也可以轻松实现这一效果,甚至也可实现类似Android典型界面设计(3)的双导航效果。可见ActionBar还是比较强大的,关键要深入进去、灵活的运用,下面我们就使用ActionBar实现如图所示的效果: 二、本例特点 1、  兼容低版本 2、 使用...

Xamarin.Forms 启动App时获取屏幕宽高

启动App时获取屏幕宽高 App.cs里面添加: publicstaticdoubleScreenWidth; publicstaticdoubleScreenHeight; Android下 MainActivity.cs里面添加: protectedoverridevoidOnCreate(Bundlebundle) { TabL...

Android开发5:应用程序窗口小部件App Widgets的实现

前言   本次主要是实现一个Android应用,实现静态广播、动态广播两种改变 widget内容的方法,即在上篇博文中实验的基础上进行修改,所以此次实验的重点是AppWidget小部件的实现啦~   首先,我们简单说一下Widget是一个啥玩意~   应用程序窗口小部件(Widget)是微小的应用程序视图,可以被嵌入到其它应用程序中(比如桌面)并接收周期...

ios 加载.bundle文件里的图片

这个是加载bundle里面的的图片 + (UIImage *)imageNamed:(NSString *)name ofBundle:(NSString *)bundleName { UIImage *image = nil; NSString *image_name = [NSString stringWithFormat:@"%@.png", nam...

android listview 的监听事件

今天遇到了一个比较让我头疼的问题,不过追根揭底只是我对listview理解的不够透彻罢了, 闲言少叙,说说我遇到的问题吧: 上篇随笔我写了关于listview的使用,如果你也已经写好了列表那么恭喜这一篇对你也有用 当然如果你还没有搭好可以先去看看我的上一篇(上篇地址:http://www.cnblogs.com/wobeinianqing/p/506474...

Bundle是个好东西

这里说的Bundle,是software library范畴的,我把它定义为: 一系列版本兼容的软件库。 对于比较小的项目,用的library不多,升级不勤快,这不是个问题,但是对于大型项目,bundle是非常有用的 - 当然,这需要build system的支持。(但加一个这样的功能蛮简单的)   bundle的格式大概为一个library=versi...