zoukankan      html  css  js  c++  java
  • 通过在xml布局文件中设置android:onClick=""来实现组件单击事件

    在布局中出现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);
            }
  • 相关阅读:
    f5版本升级
    f5申请并激活License
    f5时间设置
    f5 SNMP配置
    f5 Syslog管理
    f5单台安装配置
    f5负载均衡算法
    f5 Seldom used
    f5售后查询
    f5基本介绍
  • 原文地址:https://www.cnblogs.com/androidsuperman/p/3463991.html
Copyright © 2011-2022 走看看