解析从EditText到Button的电话号码

时间:2012-08-14 22:18:04

标签: android eclipse button

我已经知道使用按钮和edittext拨打电话号码的代码,但我不知道如何继续。

public void onClick(View arg0) {

    EditText num=(EditText)findViewById(R.id.editText1);
    String number = "tel:" +num.getText().toString().trim();
    Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(number));
    startActivity(callIntent);
}

我需要的代码允许标记为Button1的按钮解析此Intent。

1 个答案:

答案 0 :(得分:1)

Button Button1 = (Button) findViewById(R.id.button1_id);
Button1.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
             // Perform action on click
             EditText num=(EditText)findViewById(R.id.editText1);
             String number = "tel:" +num.getText().toString().trim();
             Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(number));
             startActivity(callIntent);
         }
     });
相关问题