按钮点击匿名内部类
public class MainActivity extends Activity { private EditText et_number; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //找到要操作的控件 et_number = (EditText) findViewById(R.id.editText1); Button btn_call = (Button) findViewById(R.id.button1); //给按钮添加点击事件 匿名内部类 btn_call.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //获取用户输入 String number = et_number.getText().toString().trim(); //判断输入是否为空 if(TextUtils.isEmpty(number)){ //为空提示用户 Toast.makeText(MainActivity.this, "输入不能为空", Toast.LENGTH_SHORT).show(); }else{ //不为空打电话 Intent intent = new Intent(); //指定动作 intent.setAction(Intent.ACTION_CALL); //设置数据 intent.setData(Uri.parse("tel:"+number)); startActivity(intent); } } }); } }