2012-08-14 53 views
0

我已經知道使用按鈕和edittext調用電話號碼的代碼,但我不知道如何繼續。從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。

+3

學習你的android基礎知識將幫助你解決這個問題。 – JoxTraex 2012-08-14 22:40:05

回答

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); 
     } 
    });