安卓第二天————模拟一个打电话程序
来源:互联网 发布:手机新浪博客网络异常 编辑:程序博客网 时间:2024/05/20 09:46
模拟一个打电话程序
1.在设计中,分析会发现String字符串有两个,一个text文本框,一个button按钮。
首先在res/values/strings.xml中添加两个字符串.
代码如下:
<?xml version="1.0"encoding="utf-8"?>
<resources>
<string name="hello">Hello World, PhoneActivity!</string>
<string name="app_name">Phone</string>
<string name="input_info">请输入号码:</string>
<string name="dial_caption">拨号</string>
</resources>
2.在res-layout-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"
android:layout_height="wrap_content"
android:text="@string/input_info"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id ="@+id/phone_number"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/dial_btn"
android:text="@string/dial_caption"
>
</Button>
</LinearLayout>
3.实现它
代码如下:
packagecn.class3g.activity;
importandroid.app.Activity;
importandroid.content.Intent;
importandroid.net.Uri;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.EditText;
publicclass PhoneActivity extends Activity {
/** Called when the activity is firstcreated. */
EditText numberEt;
Button dialBtn;
public void onCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViews();
dialBtn.setOnClickListener(newOnClickListener() {
@Override
publicvoid onClick(View v) {
//调用系统的拨号服务实现电话拨打功能
String phone_number =numberEt.getText().toString();
phone_number =phone_number.trim();
if(phone_number != null&& !phone_number.equals("")){
//封装一个拨打电话的intent,并且将电话号码包装成一个Uri对象传入
Intent intent = newIntent(Intent.ACTION_CALL,Uri.parse("tel:"+phone_number));
PhoneActivity.this.startActivity(intent);
}
}
});
}
public void findViews(){
numberEt = (EditText)this.findViewById(R.id.phone_number);
dialBtn=(Button)this.findViewById(R.id.dial_btn);
}
}
4.设置权限。
然后就完成了。
- 安卓第二天————模拟一个打电话程序
- 个人安卓学习笔记---Android模拟打电话程序实现
- 3G安卓应用开发——打电话应用程序
- 安卓调用打电话程序
- 安卓第二天————安卓程序的各个包下的文件的功能
- 黑马程序员:第一个Android程序——打电话
- 第二课:打电话小程序
- Android模拟打电话程序实现
- android模拟打电话程序实现
- Android模拟打电话程序实现
- 安卓 打电话
- iOS—打电话、发短信
- 安卓程序开发——创建安卓虚拟机
- 安卓巴士自测试题——第二期
- 安卓自测试题——第二期
- 安卓自测试题——第二十四期
- 安卓自测试题——第二十五期
- 安卓自测试题——第二十六期
- 人工智能幻想
- MY_Email
- shell中的wait
- http://projecteuler.net/problem=35 [Answer:55]
- Java File,object,byte[]间转换
- 安卓第二天————模拟一个打电话程序
- Lettuce简介(一)
- Android Surfac eFlinger process 流程分析
- 12/05,12/06 ----XML篇
- listview edittext 焦点
- 调试服务程序的若干方法
- 12个顶极的 Ruby on Rails 教程
- 【Linux入门学习之】vi/vim编辑器必知必会
- java高新技术(二)