手机拨号器

阅读更多

main.xml

 





 

 

string.xml

 

 



    Hello World, CallActity!
    手机拨号器
    拨打此号码
    请输入手机号:

 AndroidManifest.xml

 

    

 CallActity.java

 

 

package com.pnova;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

/**
 * 手机拨号器
 * 2011-06-07
 * @author qian.long
 */
public class CallActity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btn = (Button) this.findViewById(R.id.btnCall);
        //btn.setOnClickListener(new ButtonOnClickListener());
        btn.setOnClickListener(new View.OnClickListener() {  //匿名内部类
			@Override
			public void onClick(View v) {
				 EditText txt = (EditText) findViewById(R.id.txtPhone);
				 String phone = txt.getText().toString();  //得到用户输入的手机号码
				 Intent intent = new Intent();             //意图
				 intent.setAction("android.intent.action.CALL");
				 intent.setData(Uri.parse("tel:" + phone));
				 startActivity(intent);
			}
		});
    }
    
    /*private final class ButtonOnClickListener implements View.OnClickListener {
    	public void onClick(View v) {
    		EditText txt = (EditText) findViewById(R.id.txtPhone);
			 String phone = txt.getText().toString();  //得到用户输入的手机号码
			 Intent intent = new Intent();             //意图
			 intent.setAction("android.intent.action.CALL");
			 intent.setData(Uri.parse("tel:" + phone));
			 startActivity(intent);
    	}
    }*/
}
 

 

你可能感兴趣的:(Android,XML,OS,.net)