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);
            }
  • 相关阅读:
    react-redux-reducer
    react-redux-action
    node-express-2-jade
    node-express-1
    vuex-Module
    vuex-Action(异步)
    vuex-Mutation(同步)
    vuex-getter
    vuex-state
    ##DAY7 UINavigationController
  • 原文地址:https://www.cnblogs.com/androidsuperman/p/3463991.html
Copyright © 2011-2022 走看看