2015-08-30 95 views
0

我在我的xml中創建了一個EditText和一個ButtonAndroid studio使用edittext撥號

我想在java中做的是讓用戶輸入一個數字,然後按下按鈕,然後我希望撥號程序用輸入打開。

有沒有辦法做到這一點?

Thx。

回答

0

是的,有!

你需要一個ClickListener添加到您的Button並開始呼叫意圖:

dialButton.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      if (numTxt != null && (numTxt.getText().length()>0)) {// you can add other conditions if you want 
       startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + numTxt.getText()))); 
      } 
     } 
}); 

PS:

  • dialButton是你ButtonnumTxt是你EditText

  • This是一個簡單的教程,如果你需要更多的細節。