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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:53:28+00:00 2026-05-25T12:53:28+00:00

I have taken a sample program from a book that stores the text size

  • 0

I have taken a sample program from a book that stores the text size and text. when I am running the program again, the text size is being decreased. Can anyone help me out I am new to android

 public void onClick(View v) {

             //Getting the SharedPreference object
            prefs = getSharedPreferences(prefName, MODE_PRIVATE);
            SharedPreferences.Editor editor = prefs.edit();

            // save the values in the EditText view to preferences
            editor.putFloat(FONT_SIZE_KEY, editText.getTextSize());
            editor.putString(TEXT_VALUE_KEY, editText.getText().toString());

            // Saves the values
            editor.commit();

            //Display file saved message
            Toast.makeText(getBaseContext(), "Font size saved Successfully!", Toast.LENGTH_SHORT).show();
        }
    });

// Loading the shared Prefernces object

SharedPreferences prefs = getSharedPreferences(prefName, MODE_PRIVATE);

    // Set the TextView font size to the previously saved values
    float fontSize = prefs.getFloat(FONT_SIZE_KEY, 12);

    // init the SeekBar and EditText
    seekBar.setProgress((int)fontSize);
    editText.setText(prefs.getString(TEXT_VALUE_KEY, ""));
    editText.setTextSize(seekBar.getProgress());

    seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){

        @Override
        public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) {
            // Change the font size of the EditText
            editText.setTextSize(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {

        }

    });
  • 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-25T12:53:28+00:00Added an answer on May 25, 2026 at 12:53 pm

    You cast your float fontSize to int when you pass it to seekBar.setProgress(). This makes it lose its fractional part, and therefore become smaller. Then you retrieve this rounded value back from seekBar and call editText.setTextSize() with it. Clearly it should get smaller, as the value has lost its fractional part.

    Try setting max value for your progress to be a large value (seekBar.setMax(1000000000)), call seekBar.setProgress((int)(fontSize * 10000000)) initially, and in onProgressChanged do editText.setTextSize( ((float) progress) / 10000000 ). What we do here is basically represent a floating point number in an integer form by multiplying it with a large value. See, if you multiply float 1.234 by 1000, you get 1234.0, which can now be converted to int without any loss of factional part. To convert it back, we first convert our int 1234 to float 1234.0, then divide by 1000. And since your original program worked with percent values in progress bar, we set the maximum value to be 100 times larger than the coefficient we use to convert numbers between int and float forms. This way we preserve the original functionality of your program.

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

Sidebar

Related Questions

I have a program that records audio from firewire device (FA-66) with Jack connection.
I have a program Sample which takes input both from stdin and a non-standard
I used to have a simple ajax that helped me take all items from
I have taken a copy of a database home with me so I can
I have taken an image from UIImagePickerController , but the file looks too big
I have a program that operates on a large set of experimental data. The
I have the following shader taken from the android SDK sampele: final String vertexShader
I have used BluetoothChatService class from BluetoothChat example program for bluetooth connection. I have
I'm making a simple program to interact with a database. I have taken a
I have written a program that will be distributed for free and I am

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.