On 24 August 2011 17:05, bdk <[email protected]> wrote: > Hi > > I'm showing the user a "Save as..." dialog to save files, and I'd like > to disable a set of 'reserved characters' into a related EditText > field. > > Let's say, something like: > > private static final String ReservedChars = "|\\?*<\":>+/'¥"; > > (useful read: http://en.wikipedia.org/wiki/Filename ) > > I have to be careful not to use chars not compatible with other > filesystems like Windows (for instance: ? or " would make the file > unusable in a Win* filesystem) > > Moreover, I don't want the user to be able to put sequences like "../" > or "/foo/bar/filename.xxx" to access other paths. > > This also brings up another point: _all_ possible filepath separators > should be forbidden (for instance, ¥ is the filepath separator on > Japanese locale computers). > > So, what would be the most elegant solution to filter out these > characters from user input? > I'm also thinking about automatically replacing the forbidden chars > with underscores, but it's not really user-friendly. > > I looked into > http://developer.android.com/reference/android/text/InputType.html > but something like InputType.TYPE_CLASS_FILE_NAME is missing... > > TYPE_TEXT_VARIATION_URI does not seem an option since apparently the > soft keyboard ends up containing chars like: / * " ? ¥ and... smileys? > > For now I've tried with: > > EditText myEditText = new EditText(activity); > myEditText.setSingleLine(); > myEditText.setInputType(InputType.TYPE_CLASS_TEXT | > InputType.TYPE_TEXT_VARIATION_URI); > > to no luck. > > Now I'm reading across: > http://stackoverflow.com/questions/6626283/how-to-use-inputconnectionwrapper > ... > > best >
Just add a listener to EditText. In the listener you capture the text change event and filter through only allowed characters. -- Daniel Drozdzewski -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

