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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:30:05+00:00 2026-05-30T04:30:05+00:00

In an Android app I let the user edit his preferences by running a

  • 0

In an Android app I let the user edit his preferences by running a class which extends PreferenceActivity.
In res\xml I have a file – preferences.xml – which has an xml-description of which fields the user can configure. Things like usernames and passwords. A sample snippet:

<EditTextPreference android:name="User Name"
android:summary="Name in Your Name/Company format"
android:defaultValue="" android:title="Login name" android:key="userName" 
android:id="@+id/userName"/>

<EditTextPreference android:name="Password"
android:summary="Your web password" android:defaultValue=""
android:title="Login password" android:password="true" android:key="userPassword" 
android:id="@+id/userPassword"/>

Things are working as expected. From my main app code I can access the values that the user has configured.

There is one thing that I hope to get some good advice on how to handle: Removing leading and trailing blank spaces in the preferences-values.

By user error or because of helpful keyboard apps, sometimes users enter an extra blank character in EditTextPreferences fields. Either as the first or the last character.

I would prefer if such obvious typing errors could be removed no later than when the user exits the PreferenceActivity.
I would like to get suggestions on a good way of cleaning up the user’s preferences.

  • 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-30T04:30:06+00:00Added an answer on May 30, 2026 at 4:30 am

    Just use String.trim() on the values provided by the user, before saving them to prefs. The trim() method removes all white-space characters from the front and end of the input string.

    http://developer.android.com/reference/java/lang/String.html#trim()

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

Sidebar

Related Questions

I am building an app in android in which I am supposed to let
I'm have an app i'm working on in which I'm trying to let the
I'm writing an Android application which requires the user to login. I have a
I have an app that uses the Android licensing. I'm using the ServerManagedPolicy which
My Android app consists of a simple tablayout (3 tabs). Let's say the user
We have an Android app and a Web Service. We want to download part
I have an Android app with a ListActivity in the main view. The list
I've got an Android app which has a periodic background Service. I want this
i've developed an android app that's fetches an xml file and displays this data
I am working on an Android app that has multiple screens the user will

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.