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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:49:42+00:00 2026-06-03T06:49:42+00:00

I have a ListActivity containing Items which are fetched from a JSON Object. When

  • 0

I have a ListActivity containing Items which are fetched from a JSON Object.
When the user click one of the item, each item displays its details and attributes inside a DetailActivity class.

So I have one Activity to display the selected Item’s attributes from the ListActivity.
On the DetailActivity class there is a CheckBox, to mark the the Item as ‘Favorite’. So every time the CheckBox inside the DetailActivity is checked, when the user opens the DetailActivity of that Item again, the state of the CheckBox is always checked.

I implemented so far by putting Boolean through SharedPreferences. But my method only saves the state of the DetailActivity class regardless which Item isChecked as favorite. So it doesn’t save the state of a certain item, only the state of DetailActivity class.

How am I am able to do so?

Here is my snippet:

final CheckBox cb_fav = (CheckBox) findViewById(R.id.cb_tool_fav);
        cb_fav.setOnClickListener(this);
        boolean isChecked = getBooleanFromPreferences("isChecked");
        Log.i("start",""+isChecked);
        cb_fav.setChecked(isChecked);

        cb_fav.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
            @Override
            public void onCheckedChanged(CompoundButton buttonView,
            boolean isChecked) {
                Log.i("boolean",""+isChecked);
                DetailsActivity.this.putBooleanInPreferences(isChecked,"isChecked");

            }
            });

    }

     public void putBooleanInPreferences(boolean isChecked,String key){
            SharedPreferences sharedPreferences = this.getPreferences(Activity.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putBoolean(key, isChecked);
            editor.commit();        
        }
        public boolean getBooleanFromPreferences(String key){
            SharedPreferences sharedPreferences = this.getPreferences(Activity.MODE_PRIVATE);
            Boolean isChecked = sharedPreferences.getBoolean(key, false);
            return isChecked;       
        }

Here’s the object class I’m fetching to my ListActivity, these are the attributes which are displayed inside the DetailsActivity class.

public class VideoLocation {

    public String deleted_at = null;
    public int documentary_video_length = -1;
    public int id = -1;
    public double latitude = 0d;
    public double longitude = 0d;
    public int position = -1;
    public String updated_at = null;
    public String name = null;
    public String text = null;
    public String documentary_video_url = null;
    public String documentary_thumbnail_url = null;
    public String audio_text_url = null;
    public Footage[] footages = null;

    public VideoLocation(){

    }
  • 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-03T06:49:43+00:00Added an answer on June 3, 2026 at 6:49 am

    Ofcourse, you need to save the checkbox state of each item.

    From the attributes, i believe that “id” attribute is unique for each object. So you can save the state of the object by “id” attribute in following way:

    putBooleanInPreferences(check_uncheck,String.valueOf(videoLocationObject.id));
    

    Now whenever, you are displaying the object, you can retrieve the state in following way:

    boolean check_uncheck=getBooleanFromPreferences(String.valueOf(videoLocationObject.id));
    

    If “id” attribute is not unique, then select the attribute which is unique for each row as a key for your SharedPreferenceStorage.

    Your code:

    final CheckBox cb_fav = (CheckBox) findViewById(R.id.cb_tool_fav);
    
            boolean isChecked = getBooleanFromPreferences(String.valueOf(yourObject.id));
            Log.i("start",""+isChecked);
            cb_fav.setChecked(isChecked);
    cb_fav.setOnClickListener(this);
    
            cb_fav.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
                @Override
                public void onCheckedChanged(CompoundButton buttonView,
                boolean isChecked) {
                    Log.i("boolean",""+isChecked);
                    putBooleanInPreferences(isChecked,String.valueOf(yourObject.id));
    
                }
                });
    

    I hope this will be helpful to you.

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

Sidebar

Related Questions

I have a customized TabView which displays a ListActivity , but everytime I click
I have one android activity which extends ListActivity. Every time list items is pressed
I have a ListActivity which gets its data from a database query. I also
I have a ListActivity that's populated with a SimpleCursorAdapter which pulls the data from
I have a ListActivity which shows list of items. I prepared another layout for
I have a ListActivity in Android. Each row is just an item that starts
I have an ListActivity which use data from DB.. setListAdapter(new CursorAdapter(myCursor)); This view have
I have ListActivity , onClick of each item a Custom Dialog appears. Custom Dialog
I have a ListActivity containing an object I've defined called a MessageItem. I want
I have a ListActivity which lists a bunch of things. If you click on

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.