Asked  6 Months ago    Answers:  5   Viewed   52 times

I want to restrict the chars to 0-9, a-z, A-Z and spacebar only. Setting inputtype I can limit to digits but I cannot figure out the ways of Inputfilter looking through the docs.

 Answers

99

I found this on another forum. Works like a champ.

InputFilter filter = new InputFilter() {
    public CharSequence filter(CharSequence source, int start, int end,
            Spanned dest, int dstart, int dend) {
        for (int i = start; i < end; i++) {
            if (!Character.isLetterOrDigit(source.charAt(i))) {
                return "";
            }
        }
        return null;
    }
};
edit.setFilters(new InputFilter[] { filter });
Tuesday, June 1, 2021
 
turson
answered 6 Months ago
26

From a note in the documentation:

$workbook->setVersion(8); // Use Excel97/2000 Format
$worksheet->writeString(0, 0, $str);
Wednesday, March 31, 2021
 
Sidarta
answered 9 Months ago
54

Actually the hint moves to the parent view TextInputLayout that surrounds the EditText view:

You can get the hint like this:

android.support.design.widget.TextInputLayout parent = (android.support.design.widget.TextInputLayout) yourEditText.getParent();
String hint = parent.getHint().toString();

And if you want to add * make it like this:

parent.setHint(parent.getHint() + "*");

Happy codding! :)

Wednesday, August 4, 2021
 
Juriy
answered 4 Months ago
29

I found this method from GridLayout: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.0_r1/android/widget/GridLayout.java#GridLayout.spec%28int%2Cfloat%29

So maybe you could try something like this:

((GridLayout.LayoutParams) this.getLayoutParams()).columnSpec =
    GridLayout.spec(GridLayout.UNDEFINED, 1f);
Friday, September 24, 2021
 
Georges Dupret
answered 2 Months ago
66

You are looking for TextWatcher:

    youredittext.addTextChangedListener(new TextWatcher()
    {
        @Override
        public void afterTextChanged(Editable mEdit) 
        {
            text = mEdit.toString();
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after){}

        public void onTextChanged(CharSequence s, int start, int before, int count){}
    });
Saturday, October 9, 2021
 
freeMagee
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share