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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:46:04+00:00 2026-06-04T20:46:04+00:00

I’m trying out to save the text size in shared preference ,while running the

  • 0

I’m trying out to save the text size in shared preference ,while running the project my application stops unexpectedly here is the code :
SharedPreferenceActivity.class

package com.SharedPreference;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SeekBar;

public class SharedPreferenceActivity extends Activity 

{

SeekBar seek=(SeekBar)findViewById(R.id.seekBar1);
EditText ed1=(EditText)findViewById(R.id.editText1);
Button b=(Button)findViewById(R.id.button1);
private final String TEXT_VALUE_KEY="textvalue";
private final String FONT_SIZE_KEY="fontsize";
final String MyPref="preference";

/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState)
 {

super.onCreate(savedInstanceState);
setContentView(R.layout.main);  
b.setOnClickListener(new View.OnClickListener() {

 @Override
 public void onClick(View arg0) {

SharedPreferences  pref=getSharedPreferences(MyPref,MODE_PRIVATE);              
SharedPreferences.Editor editor=pref.edit();            
editor.putFloat(FONT_SIZE_KEY,ed1.getTextSize());           
editor.putString(TEXT_VALUE_KEY, ed1.getText().toString());         
editor.commit();

}

});

 SharedPreferences prefs=getSharedPreferences(MyPref, MODE_PRIVATE);

 final float fontsize=prefs.getFloat(FONT_SIZE_KEY, 12);

 seek.setProgress((int) fontsize);

 ed1.setText(prefs.getString(TEXT_VALUE_KEY, "")); 

 ed1.setTextSize(seek.getProgress());

 seek.setOnSeekBarChangeListener(new  SeekBar.OnSeekBarChangeListener() {


public void onStopTrackingTouch(SeekBar arg0) {

// TODO Auto-generated method stub

            }

            public void onStartTrackingTouch(SeekBar arg0) {
                // TODO Auto-generated method stub

            }

            public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
                // TODO Auto-generated method stub
                ed1.setTextSize(fontsize);
            }
        });
    }
}

XML file:

<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"

 android:layout_width="fill_parent"

 android:layout_height="fill_parent"

 android:orientation="vertical" >

<TableRow >


  <SeekBar

     android:id="@+id/seekBar1"

   android:layout_width="match_parent"

   android:layout_height="wrap_content" />


</TableRow>

<TableRow >

<EditText

   android:id="@+id/editText1"

  android:layout_width="match_parent"

  android:layout_height="150dp"

  android:layout_weight="0.6"

  android:ems="10" ></EditText>


</TableRow>

<TableRow >

 <Button

 android:id="@+id/button1"

  android:layout_width="50dp"

 android:layout_height="50dp"

 android:text="Button" />

</TableRow>

</TableLayout>
  • 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-04T20:46:05+00:00Added an answer on June 4, 2026 at 8:46 pm

    find the views in your onCreate method.

    public void onCreate(Bundle savedInstanceState)
    {
     super.onCreate(savedInstanceState);
    
     setContentView(R.layout.main);
     seek=(SeekBar)findViewById(R.id.seekBar1);
     ed1=(EditText)findViewById(R.id.editText1);
     b=(Button)findViewById(R.id.button1);
     ...
     ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a reasonable size flat file database of text documents mostly saved in
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

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.