예제 #1
0
  private View createCheckBox(ViewGroup parent, MethodInfo methodInfo) {
    final Method method = methodInfo.getMethod();
    final Object instance = methodInfo.getInstance();
    final Context context = parent.getContext();

    View view = inflater.inflate(R.layout.item_settings_checkbox, parent, false);
    ((TextView) view.findViewById(R.id.title)).setText(methodInfo.getTitle());
    CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkbox);
    checkBox.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            try {
              method.invoke(instance, isChecked);
            } catch (Exception e) {
              Log.e("Bee", e.getMessage());
            }

            PrefHelper.setBoolean(context, method.getName(), isChecked);
          }
        });
    checkBox.setChecked(PrefHelper.getBoolean(context, method.getName()));

    return view;
  }