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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:41:15+00:00 2026-05-26T13:41:15+00:00

I currently have a custom listview with two rows of text in each item,

  • 0

I currently have a custom listview with two rows of text in each item, one for the current time and one for the text the user inputs. I do this through creating a new hashmap and adding to the <ArrayList<HashMap<String,String>> that the listview uses. I would like to save my data into the sharedPreferences but I only seem to be getting the last input from the user. My question is: is there anyway to extract the data from a listview then add it into the sharedpreferences? Or add the data in the arraylist into the sharedpreferences?

Here is my code below:

@Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main_feed);


            //create button and implement on click listener
            sendButton = this.findViewById(R.id.sendPostButton);
            sendButton.setOnClickListener(this);

            //create text field and add text change listener
            postTextField = (EditText)findViewById(R.id.postTextField);
            postTextField.addTextChangedListener(TextEditorWatcher);


            //create text views for seeing the posts and character count
            currentTimeTextView = (TextView)findViewById(R.id.postTimeTextView);
            mainPostTextView = (TextView)findViewById(R.id.postTextView);
            characterCountView = (TextView)findViewById(R.id.charsleft);
            characterCountView.setText("150 chars left");

            //text view for event name and set the text
            feedName = (TextView)findViewById(R.id.nameOfFeed);
            currentFeedName = CreateFeedActivity.eventFeedName;
            feedName.setText(currentFeedName);

            list = new ArrayList<HashMap<String,String>>();

            //create the adapter for the list view
            adapter = new SimpleAdapter(
                    this,
                    list,
                    R.layout.post_layout,
                    new String[]{"time", "post"},
                    new int[]{R.id.postTimeTextView, R.id.postTextView});

            //set list adapter 
            setListAdapter(adapter);

            //place the current feed number into a variable here
            currentFeedCount = CreateFeedActivity.feedCount;

            //create the hashmap for the list view
            feedPostMap = new HashMap<String, String>();

            //place the stored data into the view again if activity has already been created
            if (LiveFeedrHomeActivity.feedOccurs == 1){ 
                Log.d(TAG, "in feed occurs is 1");

                //get the shared pref
                sharedPref = getSharedPreferences(MY_FEED, 0);
                Map<String, ?> map = new HashMap<String, String>();
                map = sharedPref.getAll();

                //convert from the map to the hashmap
                feedPostMap = (HashMap<String, String>) map;

                //add to the list
                list.add(feedPostMap);

                //refresh the adapter
                adapter.notifyDataSetChanged();

                Log.d(TAG, "feedmap get all");






            }

            //make variable feed = 1 so that you can't create another feed
            LiveFeedrHomeActivity.feedOccurs = 1;


     }

@Override
    public void onClick(View button) {
        switch(button.getId()){
        case R.id.sendPostButton:

            //create date
            date = new Date();

            //get current time
            currentTime = new SimpleDateFormat("h:mm aaa").format(date);

            SendToDatabase();

            DisplayUserInput();

            break;
        }



@Override
    public void onStop() {
        super.onStop();
        Log.d(TAG, "on stopp'd");

        //get shared pref settings
        sharedPref = getSharedPreferences(MY_FEED, 0);
        sharedPrefEditor = sharedPref.edit();



        //get the items in the hash map and add it to the 
        //shared preferences
        for (String string : feedPostMap.keySet()){
            sharedPrefEditor.putString(string, feedPostMap.get(string));

    //  }
        sharedPrefEditor.commit();



    }
  • 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-26T13:41:15+00:00Added an answer on May 26, 2026 at 1:41 pm

    I think your problem is, this for loop,

    for (String string : feedPostMap.keySet()){             
    sharedPrefEditor.putString(string, feedPostMap.get(string));      
      } 
    

    so try,

    Set<String> s = new HashSet<String>();
       for (int i=0;i<list.size();i++){      
           s.add(list.get(i).get(string));     
       } 
    
     sharedPrefEditor.putStringSet(stringSet, s); 
    

    Try this, for set of string to edit in sharedpreference,

    putStringSet(String key, Set<String> values) 
    

    Set a set of String values in the preferences editor, to be written back once commit() is called.

    for more info look at Android-SharedPreferences

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

Sidebar

Related Questions

I currently have a custom listview where each item on the list contains two
I currently have a simple list view adapter that holds two rows of text.
I have a custom listview which changes size when one of the rows is
Is it possible to apply a custom background to each Listview item via the
So I have a custom ListView object. The list items have two textviews stacked
I currently have a ListView with a custom adapter that gets information describing the
I have created a custom listview which has Image + Text + checkbox. How
I'm looking into some XSS prevention in my Java application. I currently have custom
I currently have a custom themed blog running on wordpress with Jetpack installed. I
I currently have a custom TabItem which has a custom header, which is defined

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.