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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:47:33+00:00 2026-06-14T21:47:33+00:00

I have created activity which extends preferenceActivity. In that activity I have opened custom

  • 0

I have created activity which extends preferenceActivity. In that activity I have opened custom dialog which shows list of item. Whenever i click on item in listview , dialog closed. At that time i want to store the selected item in SharedPreference so that i an get that item in application wide.

But my problem is How do i store that selected item in SharedPreference ??

And when i open my application next time, i should able to retrive previous seleced item.

Here is my code for PreferenceActivity :

public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener 
{
    SharedPreferences myprefs;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.settings);
        addPreferencesFromResource(R.xml.prefs);

        PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);

        Preference prefereces=findPreference("alertdialog_Font_Style");
        prefereces.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            public boolean onPreferenceClick(Preference preference) {
                // TODO Auto-generated method stub
                DialogFontStyle objdialog = new DialogFontStyle(SettingsActivity.this,R.style.CustomDialogTheme);
                objdialog.show();
                return true;
            }


        });
    }

Here is my class for dialog :

public class DialogFontStyle extends Dialog {

    public DialogFontStyle(Context context, int theme) {
        super(context, theme);
        // TODO Auto-generated constructor stub
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.dialog_layout);

        final String[] sizeType = new String[] {"a" , "b" , "c" , "d"};       

            final ListView lst = (ListView)findViewById(android.R.id.list);

            ArrayAdapter<String> adapter = new ArrayAdapter<String> (context,android.R.layout.simple_list_item_1,sizeType);                  
         lst.setAdapter(adapter);

             lst.setOnItemClickListener(new OnItemClickListener() {
                 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                        long arg3) {
                    // TODO Auto-generated method stub

                    dismiss();
                }
             });
    } 
}

Please give me some solution to store data in sharedpreference.
Thanx.

  • 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-14T21:47:34+00:00Added an answer on June 14, 2026 at 9:47 pm

    To write something to share preferences use this code:

    SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences( mContext );
    SharedPreferences.Editor editor = mPrefs.edit();
    editor.putBoolean( KEY, VALUE );
    editor.commit();
    

    mContext should be context of your activity or application not dialog. Or if your dialog is within your activity use SettingsActivity.this or create class member mContext and initi in on onCreate()

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

Sidebar

Related Questions

I have created a custom workflow activity that copies attachments from a case to
I have created an abstract class FbActivity, which extends Activity to connect to facebook
I have created an abstract class which extends the Activity Class. I want to
I have created two classes: Example1 and Example2 , which extends activity. Example1 contains
I have created an activity which sends a number of notifications to status bar.
I have created an Activity that will behave like a popup menu is actually
I have created one class as public class FormActivity extends Activity { TextView tv
Assume that i have created a client TCP Socket in Activity A. I want
I have an Activity that should only get created once. That is, onCreate can
Hi I have created an activity which pulls data from json format text and

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.