我在onFocusChangeListner的listview中驗證Edittext時遇到問題。如何在ListView中的EditText中進行驗證?
我的UI看起來像這樣
MeterName Previous CurrentReading
Meter1 100 Here i want to type current reading
當我鍵入當前的讀數就會與以前的讀數進行比較。當前讀數不能小於以前。如果它比以前少,那麼我想提醒用戶並且重點放在同一個EditBox上。
我的代碼是在這裏:
public void onFocusChange(View v, boolean hasFocus) {
try {
Previous_Reading = getArray_Meter_Reading.getJSONObject(holder.ref)
.getString("PrevMeterReading").toString();
Cumulative = getArray_Meter_Reading
.getJSONObject(holder.ref).getString("Cumulative")
.toString();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(!hasFocus){
int Current=Integer.valueOf(holder.adp_Current.getText().toString());
Previous=Integer.parseInt(Previous_Reading);
if(Current< Previous){
AlertDialog.Builder builder = new AlertDialog.Builder(
context);
builder.setTitle("WARNING");
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setMessage("Please Enter UserName");
builder.setPositiveButton("ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
// Caption.requestFocus();
}
});
AlertDialog diag = builder.create();
diag.show();
}
}
} });
有了這個代碼,當我開始在編輯框警報鍵入將顯示所有的角色,這是我鍵入一樣,如果以前是600,我輸入電流讀數像從圖6然後向我顯示alertdialog,然後再次alertdialog,直到它大於以前的值。
當我點擊EditText時,hasFocus爲true,當我輸入任何數字時,說5焦點更改爲false。
任何人可以告訴我如何通過給出示例代碼做驗證嗎?
如何可以一次得到編輯框孔文本,然後驗證它機智以前的價值,因爲,當我鍵入任意一個數字onfocuschangeListner得到調用和所有的數字錯誤信息提示,直到它比以前更大。 – 2012-02-18 10:02:35