Implement "Add to favourites" from icon in cardview android -


in app, add favourites icon inside cardview. on clicking icon, card should added my favorites list , icon should toggle different colour.

on clicking again should removed favourites. want accomplish task through sharedpreference.

how should proceed sequentially accomplish task?

  1. hope have layouts done. if not - create them. make sure favourites togglebutton
  2. create adapter listview or recyclerview
  3. inside adapter, when binding views, call:

         findviewbyid(r.id.btn_favourite).setonclicklistener(new view.onclicklistener() {     public void onclick(view view) {         if(view.isselected) {              markasfavourite(item);         } else {              removefromfavourites(item);         }     }     }); 

    where item object representing data list

  4. implement markasfavourite(item); , removefromfavourites(item); methods. here rough example of markasfavourite(item) using sharedpreferences.

         set itemids = msharedpreferences.edit().getstringset(key, new set());     itemids.put(item.getid);     msharedpreferences.edit().putstringset(itemids).commit(); 
  5. update data in favourites listview.

5.1 item ids sharedpreferences

5.2 select item's sub-list according ids.

5.3 update adapter favouriteslist.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -