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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:08:05+00:00 2026-06-16T22:08:05+00:00

i tried searching for an answer but could not find what i was looking

  • 0

i tried searching for an answer but could not find what i was looking for:
this was my first try at saving data/using SharedPreferences so i wasnt quite sure of what i was doing.
The main point was so that after a user inputs something in the EditText, it populates the ListView. But i also want it so that when this is carried out, the app also saves the string so that I can use LoadPreferences to have it when a user re-enters the app. This does not happen though

the code:

public class TaskPage extends SherlockActivity {

EditText display;
ListView lv;
ArrayAdapter<String> adapter;
Button addButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    display = (EditText) findViewById(R.id.editText1);
    lv = (ListView) findViewById(R.id.listView1);
    addButton = (Button) findViewById(R.id.button1);


    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
    lv.setAdapter(adapter);
    LoadPreferences();


    addButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String task = display.getText().toString();


                adapter.add(task);
                adapter.notifyDataSetChanged();
                SavePreferences("LISTS", task);
        }
    });
}

protected void SavePreferences(String key, String value) {
    // TODO Auto-generated method stub
    SharedPreferences data = PreferenceManager.getDefaultSharedPreferences(this);
    SharedPreferences.Editor editor = data.edit();
    editor.putString(key, value);
    editor.commit();


}

protected void LoadPreferences(){
    SharedPreferences data = PreferenceManager.getDefaultSharedPreferences(this);
    String dataSet = data.getString("LISTS", "None Available");

}

Im quite sure that i did something wrong but there are no errors. so when i run the app, everything works except nothing is saved(or maybe it just does not show in the ListView)

So how can i fix this?
Thanks!

  • 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-16T22:08:06+00:00Added an answer on June 16, 2026 at 10:08 pm

    Change you LoadPreferences() method as :

    protected void LoadPreferences(){
        SharedPreferences data = PreferenceManager.getDefaultSharedPreferences(this);
        String dataSet = data.getString("LISTS", "None Available");
    
         adapter.add(dataSet);
         adapter.notifyDataSetChanged();
    }
    

    in your current code you are not adding dataSet to ArrayAdapter

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

Sidebar

Related Questions

I tried searching but could not find an answer for this. I am trying
I tried searching for this in many places, but could not find an answer.
I tried searching in google but could not find any useful answer, if(verifier.length() >
I have tried searching for this forever, but unfortunately I could not find the
I have tried to find an answer to this, but could not find one
I tried searching, but did not find a specific post that could answer my
I've tried searching for an answer to this problem, but I'm not entirely sure
I'm not entirely sure if this is possible and tried searching but couldn't find
First post here, I have tried searching but couldn't find what I'm looking for
I have tried searching for this but couldn't really find a proper answer. I

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.