java - Adding values to SharedPreferences from a Custom ListViewAdapter -


i'm trying add values sharedpreferences list, idea when user click on button list item added favorites page, i'm not able so, believe problem because i'm using custom listviewadapter, listview allows me swipe list item left shows button. like so can't put sharedpreferences work in class, have:

public class listviewadapter extends baseswipeadapter {      arraylist<hashmap<string, string>> array = todasascategorias.getlistacategorias();     string designacao, k_produto;     public static final string favoritos = "favoritos";      private context mcontext;      public listviewadapter(context mcontext) {         this.mcontext = mcontext;     }      @override     public int getswipelayoutresourceid(int position) {         return r.id.swipe;     }      @override     public view generateview(final int position, viewgroup parent) {         final view v = layoutinflater.from(mcontext).inflate(r.layout.list_item_cat, null);         swipelayout swipelayout = (swipelayout) v.findviewbyid(getswipelayoutresourceid(position));         v.findviewbyid(r.id.imgbtnfav).setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view view) {                 designacao = (array.get(position)).get("designacao");                 k_produto = (array.get(position)).get("k_produto");                 toast.maketext(mcontext, "adicionado aos favoritos", toast.length_long).show();                  sharedpreferences.editor editor = getsharedpreferences(favoritos, mode_private).edit();                 editor.putstring("designacao", designacao);                 editor.apply();              }         });          return v;     }      /*....*/ } 

it keeps giving me same errors, cannot resolve method 'getsharedpreferences(java.lang.string, ?)' , cannot resolve symbol 'mode_private'

really need here, can't find in web me :/

getsharedpreferences() needs context accessed.

mcontext.getsharedpreferences 

try

sharedpreferences.editor editor = mcontext.getsharedpreferences(favoritos, mode_private).edit(); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -