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 7521615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:16:44+00:00 2026-05-30T02:16:44+00:00

I want to validate an EditTextPreference value to be inside a specific int range

  • 0

I want to validate an EditTextPreference value to be inside a specific int range (lets say 1 to 22). The only part that I could validate was the inputType (number only) with the following xml declaration in the prefs.xml file.

android:inputType=”number”

The second thing that I did is to write the following code in the ListSettings activity.

public class ListSettings extends PreferenceActivity implements OnSharedPreferenceChangeListener{

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.prefs);
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    sp.registerOnSharedPreferenceChangeListener(this);
}
 public void onSharedPreferenceChanged(SharedPreferences sp, String key) {
        String value = sp.getString(key, null);
        int intZoomValue = Integer.parseInt(value);
        if (intZoomValue < 1 || intZoomValue > 22) {
            Intent intent = new Intent().setClass(this, dialog.class);
            // I want to call the dialog activity here...
        }

  }

and the dialog.class is the following:

public class dialog extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  AlertDialog.Builder builder = new AlertDialog.Builder(this);
  builder.setMessage("Please enter a value between 1-22!");
  builder.setCancelable(true);

  AlertDialog alert = builder.create();
  alert.show();
  }
}

What I want to achieve is to call the dialog.class (the alert dialog box) whenever the user enters a value not in the range 1-22.

I can’t really understand how to validate with the proper way.

  • 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-30T02:16:45+00:00Added an answer on May 30, 2026 at 2:16 am

    It might be more user-friendly to just clamp the value to the permitted range if an invalid value is entered, and notify the user with a Toast that you have done so.

    If your range is small, such as 1-22, then you may even consider using a Spinner instead of an EditText so that the user can’t enter an invalid value in the first place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to validate and commit the value entered in the DataGridViewCell ONLY when
I want to validate textbox so that it will accept only future date. Can
I want to validate that the value entered by a user in a textbox
I want to validate the value a user enters in a text box, so
I want to validate a condition before doing the next step, but only raise
I want to validate a registration form that accepts an email address in the
If I want to validate that a text box contains an integer greater than
I want validate a url that is a image e.g.: http://www.mydomain.com/image.jpg http://www.mydomain.com/image.png http://www.mydomain.com/image.jpeg http://www.mydomain.com/image.gif
I want to validate length and restrict Numeric, alphanumeric, and alpha characters only in
I want to validate a regular expression pattern and replace its value with my

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.