Code example for InputFilter.LengthFilter

0
        filter.addAction(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED);
        getContext().registerReceiver(mReceiver, filter);
 
        // Make sure the OK button is disabled (if necessary) after rotation 
        EditText et = getEditText();
        et.setFilters(new InputFilter[] {new LengthFilter(BLUETOOTH_NAME_MAX_LENGTH)});
        if (et != null) {
            et.addTextChangedListener(this);
            Dialog d = getDialog();
            if (d instanceof AlertDialog) {
                Button b = ((AlertDialog) d).getButton(AlertDialog.BUTTON_POSITIVE);
                b.setEnabled(et.getText().length() > 0);
            } 
        } 
    } 
 
    public void pause() { 
        EditText et = getEditText();
        if (et != null) {
            et.removeTextChangedListener(this);
Experience pair programming with AI  Get Codota for Java