0

ブール値チェック用の sharedpreferences を作成したいのですが、値が常に false を返します。sharedpreferences の正しいブール値を返す方法は?

以下は私のコードです

  public boolean getBtnState(Context context,String text)//edit to store url here and check the 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

}

sharedpreferences 値を取得するコードは次のとおりです。

 @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));
         } 
4

3 に答える 3