i create sharedpreferences boolean value check, value return false. how return correct boolean value sharedpreferences?
below code
public boolean getbtnstate(context context,string text)//edit store url here , check boolean here { sharedpreferences prefs; prefs = context.getsharedpreferences(prefs_name, context.mode_private); string favurl = getprefsfavurl(context); boolean switchstate = false; if(favurl == text) { switchstate=true; } return switchstate;//always return false here } here code sharedpreferences value
@override public object instantiateitem(final viewgroup container, final int position) { showprogress(); imageview = (imageview) findviewbyid(r.id.btn_favourite); boolean statebtnnow=sharedpreference.getbtnstate(context,murl); if(statebtnnow) { imageview.setcolorfilter(color.argb(255, 249, 0, 0));//red } else { imageview.setcolorfilter(color.argb(255, 192, 192, 192)); }
you comparing 2 string variables == operator instead use .equals() method.
if(favurl.equals(text)) { switchstate=true; } it work.
refer this question == , equals().
Comments
Post a Comment