CustomSwitchPreference.java
Go to the documentation of this file.
1 package com.introlab.rtabmap;
2 
3 import android.content.Context;
4 import android.preference.SwitchPreference;
5 import android.util.AttributeSet;
6 import android.view.View;
7 import android.view.ViewGroup;
8 import android.widget.Switch;
9 
18 public class CustomSwitchPreference extends SwitchPreference {
19 
27  public CustomSwitchPreference(Context context, AttributeSet attrs, int defStyle) {
28  super(context, attrs, defStyle);
29  }
30 
37  public CustomSwitchPreference(Context context, AttributeSet attrs) {
38  super(context, attrs);
39  }
40 
46  public CustomSwitchPreference(Context context) {
47  super(context, null);
48  }
49 
50  @Override
51  protected void onBindView(View view) {
52  // Clean listener before invoke SwitchPreference.onBindView
53  ViewGroup viewGroup= (ViewGroup)view;
54  clearListenerInViewGroup(viewGroup);
55  super.onBindView(view);
56  }
57 
63  private void clearListenerInViewGroup(ViewGroup viewGroup) {
64  if (null == viewGroup) {
65  return;
66  }
67 
68  int count = viewGroup.getChildCount();
69  for(int n = 0; n < count; ++n) {
70  View childView = viewGroup.getChildAt(n);
71  if(childView instanceof Switch) {
72  final Switch switchView = (Switch) childView;
73  switchView.setOnCheckedChangeListener(null);
74  return;
75  } else if (childView instanceof ViewGroup){
76  ViewGroup childGroup = (ViewGroup)childView;
77  clearListenerInViewGroup(childGroup);
78  }
79  }
80  }
81 
82 }
CustomSwitchPreference(Context context, AttributeSet attrs, int defStyle)
CustomSwitchPreference(Context context, AttributeSet attrs)


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:34:58