Android-View对象的点击事件处理方法

Android----View对象的点击事件处理方法
package com.example.test;

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

public class MainActivity extends Activity implements OnClickListener{
	Button bt_call;
	private EditText tv_phonenumber;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//加载布局文件
		setContentView(R.layout.activity_main);
		//查找按钮
	    bt_call = (Button) findViewById(R.id.call);
	    //查找文本框
	    tv_phonenumber = (EditText) MainActivity.this.findViewById(R.id.et_phonenumber);
	    
	    //给按钮设置点击事件  1.创建一个内部类定义点击事件
	    //bt_call.setOnClickListener(new mylisnter());
	    
	   /* bt_call.setOnClickListener(new OnClickListener() {
			//2.采用匿名内部类创建点击事件
			@Override
			public void onClick(View v) {
				callphone();
			}
		});*/
	    
	    //3.让activity实现点击事件的接口
	    //bt_call.setOnClickListener(this);
	}	
	//4.在布局文件里绑定一个点击的方法
	public void callButtonClicked(View view){
		callphone();
	}
	
	private class mylisnter implements OnClickListener{

		/*
		 * 当按钮被点击的时候,调用的方法
		 * 
		 */
		@Override
		public void onClick(View v) {
			callphone();
		}
	}
	
	private void callphone() {
		String number = tv_phonenumber.getText().toString().trim();
		if(TextUtils.isEmpty(number)){
			Toast.makeText(MainActivity.this, "请输入电话号码", Toast.LENGTH_SHORT).show();
			return;
		}
		//意图,想干一件什么事情
		Intent intent = new Intent();
		intent.setAction(intent.ACTION_CALL);
		intent.setData(Uri.parse("tel:"+number));
		
		startActivity(intent);
	}
	//接口里面未实现的方法
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.call:
			callphone();
			break;
		}
	}
}

layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <EditText
        android:id="@+id/et_phonenumber"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:inputType="phone" />

    <Button
        android:id="@+id/call"
        android:onClick="callButtonClicked"<!--布局文件设置点击事件的方法-->
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/et_phonenumber"
        android:layout_marginTop="16dp"
        android:text="@string/bt_call"/>
		
</RelativeLayout>