通过在xml布局文件中设置android:onClick=""来实现组件单击事件
16lz
2021-12-04
在布局中出现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); }
更多相关文章
- 分享:Android开发半月谈
- 提取一个带计数框的EditText
- Android(安卓)设置横屏模式显示
- Android(安卓)UI设计模式实例代码
- Android实现隐藏状态栏和标题栏
- 垂直跑马灯、滚动通知
- Android(安卓)SDK/ADT 历史版本下载地址
- Android百度地图相关内容汇总
- Android出错问题:AndroidManifest.xml:2: error: No resource ide