Questions tagged «switchcompat»

7
onCheckedChanged自动调用
我从recyclerview中有一个开关,并且从DB检索数据后数据显示在recyclerview中。打开recyclerview时,我读取了DB,并且如果DB中的字段为“ Y”,则启用该开关,否则将禁用该开关。现在问题随之而来,也调用了onCheckedchanged侦听器,我希望仅当用户手动设置开关时才调用onCheckedChanged。 在打开下面的recyclerview时执行: holder.enabledisable.setChecked(messengerRecord.get_is_valid().equalsIgnoreCase("Y")); ViewHolder类: public class viewHolder extends RecyclerView.ViewHolder implements CompoundButton.OnCheckedChangeListener{ public SwitchCompat enabledisable; public viewHolder(View v) { enabledisable = (SwitchCompat) v.findViewById(R.id.enabledisable); enabledisable.setOnCheckedChangeListener(this); ................................... ................................... 刚打开recyclerView时调用的OncheckedChanged方法: @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Log.v("ranjith","called oncheckedchanged"); MessengerRecord rec; rec = dbHelper.getRecord(descview.getText().toString()); switch (buttonView.getId()) { case R.id.enabledisable: if (isChecked) { …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.