Code example for NumberPicker

Methods: clearFocushasFocussetEnabledsetMaxValuesetMinValue, setFocusable, setFocusableInTouchMode, setOnFocusChangeListener

0
 
    private void setControlsEnabled(boolean enabled) {
        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.setEnabled(enabled);
        univEdit.setFocusable(enabled);
        univEdit.setFocusableInTouchMode(enabled);
        addrEdit.setEnabled(enabled);
        addrEdit.setFocusable(enabled);
        addrEdit.setFocusableInTouchMode(enabled);
        valueSeekBar.setEnabled(enabled);
        valueSeekBar.setFocusable(enabled);
        valueSeekBar.setFocusableInTouchMode(enabled);
    } 
 
    @Override 
    public void onItemAdded(Light light) {
        super.onItemAdded(light);
        if (nameEdit != null) {
            nameEdit.setText(light.getName());
            setControlsEnabled(true); 
        } 
        updateItemView(false); 
    } 
 
    @Override 
    public void onFocusChange(View view, boolean hasFocus) {
        showHideKeyboard(view, hasFocus);
    } 
 
    @Override 
    public void onViewCreated(View view, Bundle savedInstanceState) {
        nameEdit = (EditText)getView().findViewById(R.id.light_detail_name_edit);
        nameEdit.setOnFocusChangeListener(this);
 
        univEdit = (NumberPicker)getView().findViewById(R.id.light_detail_universe_picker);
        addrEdit = (NumberPicker)getView().findViewById(R.id.light_detail_addr_picker);
        valueLabel = (TextView)getView().findViewById(R.id.light_detail_light_value_label);
        valueSeekBar = (SeekBar)getView().findViewById(R.id.light_detail_light_value);
 
        univEdit.setOnFocusChangeListener(this);
        univEdit.setMinValue(0);
        univEdit.setMaxValue(2);
 
        addrEdit.setOnFocusChangeListener(this);
        addrEdit.setMinValue(1);
        addrEdit.setMaxValue(512);