znl_12 2013-07-12 06:16 采纳率: 0%
浏览 2407

从 OnCheckedChangeListener 的 CompoundButton中获取CheckBox key的名称

我使用接口 OnCheckedChangeListener,当点击 checbox 时 onCheckedChanged 方法被摧毁。
程序中有 10 个checkboxes。如何获取 CompoundButton 中点击的checkbox的名称?我觉得 CompoundButton 有所有需要的值,但是不知道怎么获取这个值。
例如:

<CheckBox
                    android:id="@+id/cb_mute_all_sounds"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:clickable="true"
                    android:key="nm_mute_all_sounds" />

如何获取 nm_mute_all_sounds in CompoundButton 的 key 名称?

 @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
buttonView

或者如何知道哪个已经被点击?

  • 写回答

1条回答 默认 最新

  • kity 2013-07-12 07:27
    关注

    通过ID的方式
    public void onCheckedChangeListener(CompoundButton theView, boolean checked) {
    if (theView.getId() == R.id.cb_mute_all_sounds) {
    // do something
    }
    }

    评论

报告相同问题?

悬赏问题

  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真