views:

45

answers:

2

I am creating a comma seperated file and don't want to give the user a way to confuse the app.

+1  A: 

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

LordTwaroog
+1  A: 

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
        }
    });
}
Aaron C
I can use tabs [slaps forehead]. Thanks.
JackN
Using Tabs does not necessarily solve the problem. Tabs are easily entered in text fields on Android, because many hardware keyboards have a tab key that, actually enters a tab into text fields. It probably be better to read up on good CSV formats (such as http://tools.ietf.org/html/rfc4180 ) and/or use one of dozens of available CSV libraries for Java.
RoToRa