Code example for NumberPicker

Methods: clearFocushasFocusgetValuesetEnabled, setFocusable, setFocusableInTouchMode

0
        if (!enabled) {
            if (nameEdit.hasFocus()) {
                nameEdit.clearFocus();
            } else if (univEdit.hasFocus()) {
                univEdit.clearFocus();
            } else if (addrEdit.hasFocus()) {
                addrEdit.clearFocus();
            } 
        } 
 
        nameEdit.setFocusable(enabled);
        nameEdit.setFocusableInTouchMode(enabled);
        univEdit.setFocusable(enabled);
        univEdit.setFocusableInTouchMode(enabled);
        univEdit.setEnabled(enabled);
        addrEdit.setFocusable(enabled);
        addrEdit.setFocusableInTouchMode(enabled);
        addrEdit.setEnabled(enabled);
        colorPicker.setEnabled(enabled);
        svBar.setEnabled(enabled);
 
    } 
 
    @Override 
    public void onFocusChange(View view, boolean hasFocus) {
        showHideKeyboard(view, hasFocus);
    } 
 
    @Override 
    public void onViewCreated(View view, Bundle savedInstanceState) {
        nameEdit = (EditText)view.findViewById(R.id.light_detail_name_edit);
        univEdit = (NumberPicker)view.findViewById(R.id.light_detail_universe_picker);
        addrEdit = (NumberPicker)view.findViewById(R.id.light_detail_addr_picker);
        colorPicker = (ColorPicker)view.findViewById(R.id.light_detail_color_picker);
        svBar = (SVBar)view.findViewById(R.id.light_detail_color_svbar);
 
        nameEdit.setOnFocusChangeListener(this);
        univEdit.setOnFocusChangeListener(this);
        univEdit.setMinValue(0);
        univEdit.setMaxValue(2);
        addrEdit.setOnFocusChangeListener(this);
        addrEdit.setMinValue(1);
        addrEdit.setMaxValue(512);
 
        colorPicker.addSVBar(svBar);
        colorPicker.setOnColorChangedListener(this);
 
        setControlsEnabled(false); 
 
        super.onViewCreated(view, savedInstanceState);
    } 
 
    public void updateItemView() { 
        updateItemView(true); 
    } 
 
    @Override 
    public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
        MenuInflater inflater = actionMode.getMenuInflater();
        inflater.inflate(R.menu.fragment_action_cancel, menu);
        setControlsEnabled(true); 
        return super.onCreateActionMode(actionMode, menu);
    } 
 
    @Override 
    public void onDestroyActionMode(ActionMode actionMode) {
        Object tag = actionMode.getTag();
        boolean cancelled = tag != null && tag.equals(R.string.cancelled);
        DmxColorLight light = (DmxColorLight)item;
        if (!cancelled) {
            if (!nameEdit.getText().toString().isEmpty()) {
                item.setName(nameEdit.getText().toString());
            } 
            light.setUniverse(univEdit.getValue());
            light.setAddress(addrEdit.getValue());
            light.setColor(colorPicker.getColor());
        } 
        setControlsEnabled(false); 
        super.onDestroyActionMode(actionMode);
    }