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

  • Home
  • SEARCH
  • 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 8951263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:37:23+00:00 2026-06-15T13:37:23+00:00

I have an EditTextPrefernce in my prefernces fragment. I have set it in XML

  • 0

I have an EditTextPrefernce in my prefernces fragment. I have set it in XML to be androd:numeric=”integer”. Ok that’s working…but the problem is that the user must insert a value in this preference, he can’t delete everything and click ok, because i will get null value then. I have set in the XML default value to be 10000, and in the preference.getLong method to also return a default 1000 value.

So i think i have to somehow check the edit text when the user presses ok in the dialog. Is this possible? or does anyone have a better solution?

  • 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-06-15T13:37:24+00:00Added an answer on June 15, 2026 at 1:37 pm

    Following is the snippet of the code by which you can achieve what you are looking for,

    editPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener()
                    {
                        @Override
                        public boolean onPreferenceChange(Preference preference, Object newValue)
                        {
                            try
                            {
                                //Put validation of newValue entered by user
                                //Following is example you can change as you wish
                                if(newValue != null)
                                {
                                    long myVal = Long.parseLong(String.valueOf(newValue));
                                    if(myVal> 0)
                                    {
                                        //All ok
                                    }
                                    else
                                    {
                                       //Invalid Number
                                    }
                                 }
                            }
                            catch (final Exception e)
                            {
                                return false;
                            }
                            return false;
                        }
                    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a problem that seems easy on paper but i'm having a big problem
I have a set of values defined in preference.xml: <EditTextPreference android:defaultValue=19999999999 android:key=@string/phone_number android:persistent=true android:summary=Test
I have a simple (not user-editable) numerical setting defined in a preferences XML as
I have a PreferenceActivity that loads its preferences from an XML file which looks
I am working right now with Android's SharedPreferences . I have set some preference
Have a problem, I'm about to rebuild the search feature on my site, but
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
have a nice day. I got problem when trying to create an image from
I have a specific situation, I'm using EditTextPreference in preferences to allow user to
Have a SQL problem, adding this model all works correctly, the problem is in

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.