Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7514901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:38:02+00:00 2026-05-30T00:38:02+00:00

I have problem in validating Edittext in listview in onFocusChangeListner. My UI looks like

  • 0

I have problem in validating Edittext in listview in onFocusChangeListner.

My UI looks like this

MeterName Previous CurrentReading
Meter1    100      Here i want to type current reading

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.

My code is here:

 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();
                }

           }

      } });

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.

When I click on EditText hasFocus is true and when I type any number say 5 focus changes to false.

Can any one tell me how to do validation for that by giving sample code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:38:03+00:00Added an answer on May 30, 2026 at 12:38 am

    Have a look at this . Then, extending that concept to your problem, I would suggest:

    EditText myEditText = (EditText)findViewById(R.id.first_name);
    int textValue = 0 ;
    try {
        textValue = Integer.parseInt(myEditText.getText().toString()) ;
    catch (NumberFormatException nfe) {
        // Handle the exception
    }
    if (textValue < minValue) {
        myEditText.requestFocus();
        myEditText.setError( "Value entered is lower than previous value." );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with cakephp's Session->write method. If I set a value like $_SESSION['..']
I'm building a multi-tenant app with ASP.NET MVC and have a problem with validating
This is a winform C# question. I have a textbox with a validating event
I am considering the problem of validating real numbers of various formats, because this
First of all, I have already readed this: Validating form dropdown in CodeIgniter But
I have a problem where I'm validating that the current time has been inserted
I have a problem cross validating a dataset in R. mypredict.rpart <- function(object, newdata){
The problem that I have is this: I have a lot of XSD files
I have a slight problem when it comes to validating my radio buttons. What
I have this code that updates a calendar widget and input field, while validating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.