以下代码无错误,无警告
package com.ststudy.learn002;
/**
* <uses-permission android:name="android.permission.CALL_PHONE"/>
*/
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class CallYou extends Activity {
private EditText mEtPhoneNumber;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
call();
}
public void call()
{
mEtPhoneNumber = (EditText) findViewById(R.id.etPhoneNumber);
Button mBtCall = (Button) findViewById(R.id.btCall);
mEtPhoneNumber.setOnClickListener(new MyListener());
mBtCall.setOnClickListener(new MyListener());
}
/**
* 内部类,实现本页面View对象的监听
*/
class MyListener implements View.OnClickListener
{
@Override
public void onClick(View view) {
switch (view.getId())
{
case R.id.btCall:
Intent _intent = new Intent();
_intent.setAction(Intent.ACTION_CALL);
_intent.setData(Uri.parse("tel:" + mEtPhoneNumber.getText().toString()));
startActivity(_intent);
Toast.makeText(CallYou.this,"你点击了打电话按钮",Toast.LENGTH_SHORT).show();
break;
case R.id.etPhoneNumber:
Toast.makeText(CallYou.this,"你点击了编辑框",Toast.LENGTH_SHORT).show();
break;
}
}
}
}