开发者

Is there a built in method, InputType, or other clever way to cause an Android EditText widget to refuse to accept commas?

I am creating a comma seperated file and d开发者_开发百科on't want to give the user a way to confuse the app.


Following what RoToRa said, you can delimitate the file using tabs instead.

If you do want to disallow commas, you can add a TextWatcher to modify the string before it is posted to the GUI:

EditText text;
private void foo()
{
    text.addTextChangedListener(new TextWatcher()
    {
        public void onTextChanged(CharSequence s, int start, int before, int count)
        {
        }

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

        public void afterTextChanged(Editable s)
        {
            // modify string here
        }
    });
}


Just check the addTextChangedListener(TextWatcher watcher) method - add the listener, which will check the editText field when it changes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜