我在Spinner中有3个项目。当我选择0位置输入类型时应使用特殊的过滤器,而其他两个应使用数字过滤器。第一次应用0位置过滤器。但是当我选择其他位置并出现时回到0位置仍会显示数字小键盘。
private String blockCharacterSet = "@~#^|$%&*!()?:;'-_+=|{}<>,.";
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
item_to_send = actualValues[position];
spinner_item=title[position];
//spinner_item = title[position];
if(position==0)
{
et_BTEInput.setFilters(new InputFilter[] { filter });
}
else
{
et_BTEInput.setInputType(InputType.TYPE_CLASS_NUMBER);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
private InputFilter filter = new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
if (source != null && blockCharacterSet.contains(("" + source))) {
return "";
}
return null;
}
};