繁体   English   中英

如何在android中点击各种按钮的id并进行各种操作

[英]How to get id of various buttons on click in android and perform various operations

我附上了我的布局文件的 ss。 这是我的布局

现在,当用户单击 cse 时,我想连接与 cse 相关的 api,类似地,当单击 mech 时,我想连接与 mech 相关的 api,反之亦然 如何使用任何条件语句在单个活动中完成所有这些

在点击监听器上实现。

class DepartmentActivity : AppCompatActivity(), View.OnClickListener {
...
}
  override fun onClick(view: View?) {
        when(view.id)
        {
            R.id.btnCse -> // call the required  method
            R.id.btnMech -> // call the required  method
            R.id.btnEce -> // call the required  method
            R.id.btnErr -> // call the required  method
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM