Android(java)学习笔记25:Android 手机拨号
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 手机拨号的更多相关文章
- Android开发学习笔记-关于Android的消息推送以及前后台切换
下面是最简单的Android的消息推送的实现方法 package com.example.shownotic; import java.util.Random; import android.supp ...
- Java学习笔记25(System类)
System类,系统类,包含的是静态方法,无法创建对象 这里介绍几个简单的方法,其他一些在后边用到的时候会讲 类方法: currentTimeMillis():获取当前毫秒数 package demo ...
- java学习笔记25(Collections类)
Collections算法类: Collections是一个算法类,提供了一系列静态方法,实现对集合的排序.替换.交换.搜索.拷贝等操作: 用法:Collections.方法名(要操作的集合): 就像 ...
- Android 数字签名学习笔记
Android 数字签名学习笔记 在Android系统中,所有安装到系统的应用程序都必有一个数字证书,此数字证书用于标识应用程序的作者和在应用程序之间建立信任关系,如果一个permission的pro ...
- Android动画学习笔记-Android Animation
Android动画学习笔记-Android Animation 3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中 ...
- Android:日常学习笔记(5)——探究活动(2)
Android:日常学习笔记(5)——探究活动(2) 使用Intent在活动之间穿梭 什么是Intent Intent时Android程序中各组件之间进行交互的一种重要方式,他不仅可以指明当前组件想要 ...
- Android自动化学习笔记:编写MonkeyRunner脚本的几种方式
---------------------------------------------------------------------------------------------------- ...
- Android自动化学习笔记之MonkeyRunner:官方介绍和简单实例
---------------------------------------------------------------------------------------------------- ...
- Android学习笔记1 android adb启动失败问题 adb server is out of date. killing...
下面是Android的学习笔记,原文地址. 我是使用adb devices出现如下红字错误, 使用第一种方法方法,结果关掉豌豆荚就可以了. android adb启动失败问题 adb server i ...
- Android:日常学习笔记(9)———探究持久化技术
Android:日常学习笔记(9)———探究持久化技术 引入持久化技术 什么是持久化技术 持久化技术就是指将那些内存中的瞬时数据保存到存储设备中,保证即使在手机或电脑关机的情况下,这些数据仍然不会丢失 ...
随机推荐
- Scrum3.0 敏捷开发白皮书
一.什么是敏捷? 敏捷是一种以用户需求为核心.采用不断迭代的方式进行的软件开发模式.敏捷依靠自组织 的跨职能小团队,在短周期内,做出小块的东西来,通过快速.频繁的迭代,迅速的获取反 馈,进而不断的完善 ...
- 数据插入INSERT
一.INSERT SELECT :将查询的数据直接插入 特点: 1.一次性插入所有查询出来的数据. 2.数据原子性,有一个失败全部失败. 3.没有指定的列加默认值或NULL,都没有就报错. 二.INS ...
- Mercedes BENZ C5 SD Connect Xentry Tab Kit Technical Support
Why MB Star Diagnostic tool is so well-received by thousands of users, its technology and quality is ...
- The user specified as a definer ('root'@'%') does not exist解决方案
今天操作以root身份操作MySQL数据库的时候报出了这个异常: Error updating database. Cause: java.sql.SQLException: The user spe ...
- VI设计对于企业文化建设的重要性
VI设计对于企业文化建设非常重要,包括企业品牌形象塑造.企业价值提炼.企业文化建设等有着非常重要的作用.VI设计的发展趋势是什么? 第一 从静态到动态 中国过去一段时间以来的VI设计,也是以一种静止和 ...
- Docker的基本构架
不多说,直接上干货! Docker的基本构架 Docker基于Client-Server架构,Docker daemon是服务端,Docker client是客户端. Docker的基本架构,如下图所 ...
- TOJ 3184 Mine sweeping
描述 I think most of you are using system named of xp or vista or win7.And these system is consist of ...
- 使用Git(msysgit)和TortoiseGit上传代码到GitHub
1.准备 下载Git for Windows (msysgit) 下载TortoiseGit 安装过程很简单,一直点击下一步到完成即可. 2.配置TortoiseGit 1.双击TortoiseGit ...
- node会话管理——cookie-parser
cookie是由服务器发送给客户端(浏览器)的小量信息. 我们知道,平时上网时都是使用无状态的HTTP协议传输出数据,这意味着客户端与服务端在数据传送完成后就会中断连接.这时我们就需要一个一直保持会话 ...
- Java基础之 学java从宝宝的命令行做起
JAVA学习笔记 JAVA命令行 在当前文件的命令行下 编译:输入命令javac GetGreeting.java 执行 命令 Java GetGreeting 有package包的程序 1.到文件当 ...