我有一个 edittext 应该允许 24 小时格式时间意味着 00:00 到 23:59
只剩下两个检查
1. hh 不应大于 23,mm 不应大于 59 当用户键入或移动到另一个编辑文本时,我需要检查这一点。
2.应该只有一个(最小值和最大值):符号
我正在动态创建此编辑文本代码如下
final EditText timeVisited = new EditText(this);
timeVisited.setId(20);
timeVisited.setText(Tm);
timeVisited.setTextColor(Color.BLACK);
timeVisited.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
timeVisited.setHint("eg. 14:30 for 2:30 PM");
timeVisited.setPadding(5,5,5,5);
timeVisited.setSingleLine(false);
timeVisited.setLines(1);
timeVisited.setBackgroundResource(R.drawable.text_bg);
customerToCatchTblRow.addView(timeVisited);// add the column to the table row here
LinearLayout.LayoutParams params5 = (LinearLayout.LayoutParams)timeVisited.getLayoutParams();
params5.setMargins(0, 0, 5, 0); //substitute parameters for left, top, right, bottom
timeVisited.setLayoutParams(params5);
//it checks max input is 5
int maxLength = 5;
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(maxLength);
timeVisited.setFilters(FilterArray);
//It allow only numbers and :
InputFilter filter = new InputFilter()
{
@Override
public CharSequence filter(CharSequence source, int start, int end,Spanned dest, int dstart, int dend)
{
for (int i = start; i < end; i++)
{
if (!Character.isDigit(source.charAt(i))&& source.charAt(i) != ':')
{
return "";
}
}
return null;
}
};
timeVisited.setFilters(new InputFilter[]{filter});