在main.xml中:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:background="#000000">
<EditText
android:id="@+id/tel"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"/>
<Button
android:id="@+id/mybut"
android:layout_width="80dp"
android:layout_height="40dp"
android:layout_marginTop="8dp"
android:layout_marginLeft="8dp"
android:background="#3399ff"
android:textColor="#ffffff"
android:text="拨打电话"/>
</LinearLayout>
在MyIntentCaseDemo.java中:
package com.li.intentcaseproject;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.support.v4.app.NavUtils;
public class MyIntentCaseDemo extends Activity {
private Button mybut = null;
private EditText tel = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.main);
this.mybut = (Button)super.findViewById(R.id.mybut);
this.tel = (EditText)super.findViewById(R.id.tel);
this.mybut.setOnClickListener(new OnClickListenerImpl());
}
private class OnClickListenerImpl implements OnClickListener{
public void onClick(View v) {
String telStr = MyIntentCaseDemo.this
.tel.getText().toString(); //取得输入信息
Uri uri = Uri.parse("tel:" + telStr); //设置要操作的路径
Intent it = new Intent();
it.setAction(Intent.ACTION_DIAL); //设置要操作的Action
it.setData(uri); //要设置的数据
MyIntentCaseDemo.this.startActivity(it); //执行跳转
}
}
}