android.widget.CompoundButton.OnCheckedChangeListener
我的一个程序是在主Activity A 中有一个CheckBox;但从A进入到Activity B中,在B中设置好一些参数后,返回A,这时让A中的CheckBox被选中。当然在A中也能手动让CheckBox被选中或是取消选中。
A的布局xml文件中关于CheckBox的描述是:
<CheckBox android:id="@+id/cb_time_open" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="@dimen/text_size_medium" android:layout_below="@id/btn_create_new_alarm" android:layout_marginLeft="20dip" android:layout_marginTop="5dip" android:textColor="@android:color/white" />
现在的问题是:
当第一次进入程序时,因为要恢复用户上一次设置的状态,所以要给CheckBox来setChecked(boolean)。这时就已经触发了A的CheckBox的OnChecedChangedListener了。
而且在B中设置完毕后,返回到A界面时,又要求让CheckBox.setChecked(true),又再一次触发了OnCheckedChangedListener。
而上面的这两种触发都不是我想要的,我想要的只是用户手动选中或取消勾中CheckBox时才触发。
这个主要还是逻辑上的问题。
目前还没有什么好办法,临时采取的办法时让CheckBox只负责显示是否勾中,然后写一个Button来负责取消或是增加我要的功能。
这个的好处就是不再触动OnCheckedChangedListener,只有当用户手动点击Button时才执行特定功能。