Java Code Examples for android.widget.Switch#setTag()

The following examples show how to use android.widget.Switch#setTag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FormBindings.java    From SimpleFTP with MIT License 6 votes vote down vote up
/**
 * Binding method for Switch
 * @param view The Switch widget.
 * @param observable The field value.
 */
@BindingAdapter("binding")
public static void bindSwitch(Switch view, final FieldViewModel<Boolean> observable) {
    if (view.getTag() == null) {
        view.setTag(true);
        view.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                observable.set(isChecked);
            }
        });
    }

    boolean newValue = observable.get() == null ? false : observable.get().booleanValue();
    if (view.isChecked() != newValue) {
        view.setChecked(newValue);
    }

    String newError = observable.getError();
    if (view.getError() != newError) {
        view.setError(newError);
    }
}
 
Example 2
Source File: AppRestrictionEnforcerFragment.java    From enterprise-samples with Apache License 2.0 5 votes vote down vote up
private void updateApprovals(Context context, String[] approvals,
                             String[] selectedApprovals) {
    mCurrentRestrictions.putStringArray(RESTRICTION_KEY_APPROVALS, selectedApprovals);
    mLayoutApprovals.removeAllViews();
    for (String approval : approvals) {
        Switch sw = new Switch(context);
        sw.setText(approval);
        sw.setTag(approval);
        sw.setChecked(Arrays.asList(selectedApprovals).contains(approval));
        sw.setOnCheckedChangeListener(this);
        sw.setId(R.id.approval);
        mLayoutApprovals.addView(sw);
    }
}
 
Example 3
Source File: AppRestrictionEnforcerFragment.java    From android-AppRestrictionEnforcer with Apache License 2.0 5 votes vote down vote up
private void updateApprovals(Context context, String[] approvals,
                             String[] selectedApprovals) {
    mCurrentRestrictions.putStringArray(RESTRICTION_KEY_APPROVALS, selectedApprovals);
    mLayoutApprovals.removeAllViews();
    for (String approval : approvals) {
        Switch sw = new Switch(context);
        sw.setText(approval);
        sw.setTag(approval);
        sw.setChecked(Arrays.asList(selectedApprovals).contains(approval));
        sw.setOnCheckedChangeListener(this);
        sw.setId(R.id.approval);
        mLayoutApprovals.addView(sw);
    }
}