1. 手机拨号程序:(只有程序代码)

 package cn.itcast.phone;

 import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText; public class MainActivity extends Activity implements OnClickListener {
public static final String tag ="MainActivity";
private EditText mEditText;//这里EditText实现为成员变量,在OnCreate()方法中调用它执行动作(执行一次)
@Override
public void onCreate(Bundle savedInstanceState) {//onCreate()是创建MainActivity调用的,这里的内容是指执行一次
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 得到了 activity界面上button的引用
Button button = (Button) this.findViewById(R.id.bt_dail);
mEditText = (EditText) MainActivity.this.findViewById(R.id.et_number);//这里把每次拨号查找EditText组件这一步,放到这里,
/* button.setOnClickListener(new OnClickListener() { //不用每次查找EditText,提高效率 // 方法二 :通过匿名内部类的方式实现点击事件
@Override
public void onClick(View v) { String number = mEditText.getText().toString();
Log.i(tag,number);
Log.i(tag,"匿名内部类");
//播打电话号码
Intent intent = new Intent(); // 意图 代表一个要执行动作的意图
//拨打动作 110 代表的是一个数据
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+number)); //android里面
startActivity(intent);
}
});*/ // button.setOnClickListener(this);//第三种写法,MainAcitivity implements OnclickListener{} } /**
* 第一种写法
* @author zehua
*
*/
private class MyButtonClickListener implements OnClickListener{
// 在某一个view对象 被点击的时候 调用的回调方法
@Override
public void onClick(View v) { String number = mEditText.getText().toString();
Log.i(tag,number);
//播打电话号码
Intent intent = new Intent(); // 意图 代表一个要执行动作的意图
//拨打动作 110 代表的是一个数据
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+number)); //android里面
startActivity(intent);
} } // 第三种写法:按钮对应的点击事件
// 参数 v 代表的就是当前被点击的条目对应的view对象
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.bt_dail:
//相应按钮的点击事件 String number = mEditText.getText().toString();
Log.i(tag,number);
//播打电话号码
Intent intent = new Intent(); // 意图 代表一个要执行动作的意图
//拨打动作 110 代表的是一个数据
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+number)); //android里面
startActivity(intent);
break; } } /**
* 定义 xml布局文件里面 button 绑定的点击事件的方法
* @param view
*/
public void dail(View view){
String number = mEditText.getText().toString();
Log.i(tag,number);
//播打电话号码
Intent intent = new Intent(); // 意图 代表一个要执行动作的意图
//拨打动作 110 代表的是一个数据
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+number)); //android里面
startActivity(intent);
} public void textview_click(View view){
Log.i(tag,"文本被点击了");
}
}

部署程序到虚拟机上:

附上代码中的:main.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <TextView
android:layout_width="fill_parent"
9 android:onClick="textview_click"
android:clickable="true"
android:layout_height="wrap_content"
android:text="@string/please_input_number" /> <EditText
android:id="@+id/et_number"
android:numeric="integer"
android:lines="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/hint" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bt"
android:id="@+id/bt_dail"
android:onClick="dail" />
</LinearLayout>

string.xml

 <?xml version="1.0" encoding="utf-8"?>
<resources> <string name="hello">Hello World, MainActivity!</string>
<string name="app_name">Phone</string>
<string name="please_input_number">请输入拨打的手机号码</string>
<string name="hint">请输入号码</string>
<string name="bt">拨打电话</string>
</resources>

Android(java)学习笔记25:Android 手机拨号的更多相关文章

  1. Android开发学习笔记-关于Android的消息推送以及前后台切换

    下面是最简单的Android的消息推送的实现方法 package com.example.shownotic; import java.util.Random; import android.supp ...

  2. Java学习笔记25(System类)

    System类,系统类,包含的是静态方法,无法创建对象 这里介绍几个简单的方法,其他一些在后边用到的时候会讲 类方法: currentTimeMillis():获取当前毫秒数 package demo ...

  3. java学习笔记25(Collections类)

    Collections算法类: Collections是一个算法类,提供了一系列静态方法,实现对集合的排序.替换.交换.搜索.拷贝等操作: 用法:Collections.方法名(要操作的集合): 就像 ...

  4. Android 数字签名学习笔记

    Android 数字签名学习笔记 在Android系统中,所有安装到系统的应用程序都必有一个数字证书,此数字证书用于标识应用程序的作者和在应用程序之间建立信任关系,如果一个permission的pro ...

  5. Android动画学习笔记-Android Animation

    Android动画学习笔记-Android Animation   3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中 ...

  6. Android:日常学习笔记(5)——探究活动(2)

    Android:日常学习笔记(5)——探究活动(2) 使用Intent在活动之间穿梭 什么是Intent Intent时Android程序中各组件之间进行交互的一种重要方式,他不仅可以指明当前组件想要 ...

  7. Android自动化学习笔记:编写MonkeyRunner脚本的几种方式

    ---------------------------------------------------------------------------------------------------- ...

  8. Android自动化学习笔记之MonkeyRunner:官方介绍和简单实例

    ---------------------------------------------------------------------------------------------------- ...

  9. Android学习笔记1 android adb启动失败问题 adb server is out of date. killing...

    下面是Android的学习笔记,原文地址. 我是使用adb devices出现如下红字错误, 使用第一种方法方法,结果关掉豌豆荚就可以了. android adb启动失败问题 adb server i ...

  10. Android:日常学习笔记(9)———探究持久化技术

    Android:日常学习笔记(9)———探究持久化技术 引入持久化技术 什么是持久化技术 持久化技术就是指将那些内存中的瞬时数据保存到存储设备中,保证即使在手机或电脑关机的情况下,这些数据仍然不会丢失 ...

随机推荐

  1. Python I/O及FIle方法

    一.文件操作 文件的编码格式: ASCII与UNICODE: 计算机有256个ASCII字符(8个0/1的排列组合方式一共有256种, 2**8) UTF-8是UNICODE的一种编码格式,计算机中使 ...

  2. oracle 单实例DG(搭建篇一)

    一,介绍 lodding... 二,安装前环境配置 01,依赖包的安装: yum install binutils-* yum install compat-libstdc++-* yum insta ...

  3. XLua 网络加载(基础操作)

    LoadGameMethod  网上资源加载更新:加载场景中另建协程用来加载; public void LoadGameMethod() { StartCoroutine(start());      ...

  4. (转)Cobbler无人值守批量安装Linux系统

    本文目录: 1.1 pxe安装系统 1.2 cobbler基本介绍 1.3 安装和配置cobbler 1.3.1 安装cobbler 1.3.2 配置dhcp和tftp 1.4 cobbler从本地光 ...

  5. 使用openssl在命令行加密

    对于需要在应用软件中进行加密编程的开发者,通过命令行把基本的加密操作做一遍是很有意义的.openssl支持在命令行进行各种基本加密算法的操作.这些操作过程无需编程,其命令参数与程序函数调用加密的参数有 ...

  6. ubuntu命令行添加拥有管理员权限新用户

    最近买了个服务器,只有一个root用户,天天登录挺不方便的,所以想要新建用户;之前在本地都是用界面话新建的用户,这次记录一下学习命令行新建用户的过程: 第一步 : # sudo adduser zhq ...

  7. 【Ubuntu】设置静态ip地址

    一.Ubuntu16.04设置静态IP1.获取网卡的名字   ip route show 2.获取网卡的名字 vim /etc/network/interfaces auto ens33 iface ...

  8. Csharp: FreeTextbox 编辑器控件运行时错误: 'FTB_ResizeGalleryArea' 未定义

    ftb.imagegallery.aspx 改一下代码: <form id="Form1" runat="server" enctype="mu ...

  9. 【数据库】5.0 MySQL入门学习(五)——MySQL源码了解及MySQL初始化设置

    1.0 MySQL源码目录主要包括:客户端代码.服务端代码.测试工具.其他库文件.当然,看懂源代码得有一定的C语言基础. BUILD:各种平台的编译脚本,可以用来制作各平台的二进制版本 client: ...

  10. js中的this问题

    this this的指向在函数定义的时候是确定不了的,只有函数执行的时候才能确定this到底指向谁,实际上 this的最终指向的是那个调用它的对象(这里其实并不完全对,this的指向有时候会很微妙,得 ...