在布局中出现android:onClick=""语句:

 <Button
        android:id="@+id/call_button"
        android:onClick="callphone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/phonenumber_edit"
        android:text="callme" />

在你的Activity中只要实现callphone的方法即可:

private void callPhone() {
            //代码优化之phoneNumber判断是否为空
            String phoneNumber = phonenumber_edit.getText().toString().trim();
            //判断内容是否为空
            if(TextUtils.isEmpty(phoneNumber)){
                Toast.makeText(getApplicationContext(), "内容不能为空", Toast.LENGTH_LONG).show();
                return;
            }

            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tel:"+phoneNumber));
            startActivity(intent);
        }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2022-02-08
  • 2021-11-25
  • 2022-12-23
  • 2021-11-27
猜你喜欢
  • 2021-10-14
  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案