Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to do validation in EditText within a ListView?
    text
    copied!<p>I have problem in validating Edittext in listview in onFocusChangeListner.</p> <p>My UI looks like this</p> <pre><code>MeterName Previous CurrentReading Meter1 100 Here i want to type current reading </code></pre> <p>When I type the current Reading it will compare with previous reading. Current Reading can't be less than Previous. If it is less than previous then I want to alert the user and focus is on same EditBox.</p> <p>My code is here:</p> <pre><code> 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&lt; 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(); } } } }); </code></pre> <p>With this code, when I start typing in EditBox alert is shown for all the characters, what I type like if previous is 600 and I type current reading like 6 it shows me alertdialog then 5 again alertdialog till it is greater than previous value. </p> <p>When I click on EditText hasFocus is true and when I type any number say 5 focus changes to false.</p> <p>Can any one tell me how to do validation for that by giving sample code?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload