Question

I've got a bit of a concept question I'd like to have answered.

I'm aiming to make an android application in which textboxes can only have specific types of inputs. As an example, decimal numbers are easy, you use a Number text box. However, if I were to use hexidecimal numbering system as an example, how can I have my box reject any input that is attempted to be entered that is not a valid hexidecimal character (0-F)? This concept could be extended to the octal and binary numbering systems. Ideally, the keyboard which appears when the box is clicked would only display valid characters for that particular box, but I'm not sure if that is possible.

Thanks!

K.

Was it helpful?

Solution

Overwrite the textbox listener and on key stroke, get the inputed text, run the conditions you want. If it passes, it is acceptable, if not you warn the user ..

EXAMPLE of listener:

tv = (TextView)findViewById(R.id.charCounts);
textMessage = (EditText)findViewById(R.id.textMessage);
textMessage.addTextChangedListener(new TextWatcher(){
    public void afterTextChanged(Editable s) {
    }
    public void beforeTextChanged(CharSequence s, int start, int count, int after){}
    public void onTextChanged(CharSequence s, int start, int before, int count){
        //Check if text is hexadecimal
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top