如果在单击某个EditText的时候想让其他的EditText获得输入的焦点,那么可以使用下面的语句,
getCurrentFocus().setFocusable(false);
getCurrentFocus().setFocusableInTouchMode(false);
而要获得焦点的EditText:
mSearchEdit.setFocusable(true);
mSearchEdit.setFocusableInTouchMode(true);
mSearchEdit.requestFocus();
二. 设置输入格式过滤器
为EditText设置输入的过滤器。InputFilter,首先要注意的是对一个EditText的对象设置setFilters(InputFilter[]filters),其参数是一个inputFilter数组,即对一个EditText你可以同时设置多个输入过滤器。而我们平时用的时候一般设置一个过滤器就可以了,所以可以作如下使用(以输入数字为例):
InputFilter[] mDigitsFilters = new InputFilter[1];
mDigitsFilters[0] = new DigitsKeyListener(true, true);
ps: DigitsKeyListener第一个参数是Sign,如果设置为true,表示允许在数字最左端有负号,否则只能输入正数;第二个参数是decimal,如果设置为true,表示允许在数字中有一个小数点存在。
最后setFilters(mDigitsFilters);就OK了,
InputFilter是一个接口,其实现的子类有:
DateKeyListener, DateTimeKeyListener, DialerKeyListener,DigitsKeyListener, InputFilter.AllCaps, InputFilter.LengthFilter, LoginFilter,LoginFilter.PasswordFilterGMail, LoginFilter.UsernameFilterGMail,LoginFilter.UsernameFilterGeneric, NumberKeyListener, TimeKeyListener
DateKeyListener Forentering dates in a text field.
DateTimeKeyListener Forentering dates and times in the same text field.
DialerKeyListener Fordialing-only text entry
DigitsKeyListener Fordigits-only text entry
InputFilter.AllCaps Thisfilter will capitalize all the lower case letters that are added throughedits.
InputFilter.LengthFilter Thisfilter will constrain edits not to make the length of the text greater than thespecified length.
LoginFilter Abstractclass for filtering login-related text (user names and passwords)
LoginFilter.PasswordFilterGMail Thisfilter is compatible with GMail passwords which restricts characters to theLatin-1 (ISO8859-1) char set.
LoginFilter.UsernameFilterGMail Thisfilter rejects characters in the user name that are not compatible with GMailaccount creation.
LoginFilter.UsernameFilterGeneric Thisfilter rejects characters in the user name that are not compatible with Googlelogin.
NumberKeyListener Fornumeric text entry
TimeKeyListener Forentering times in a text field.
根据解释应该不难理解,根据你自己的需要选择吧。