0

我正在使用界面OnCheckedChangeListeneronCheckedChanged当我单击复选框时会触发方法。

但我有 10 个复选框。如何获取 CompoundButton 中单击的复选框的名称。我认为这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现在如何获取密钥名称CompoundButton

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

或者你怎么知道我点击了哪个?

4

1 回答 1

2

您可以直接使用该 ID:

 public void onCheckedChangeListener(CompoundButton theView, boolean checked) {
   if (theView.getId() == R.id.nm_mute_all_sounds) {
     // do stuff
   }
 }
于 2013-03-31T15:40:25.563 回答