我想知道如何能够从我的共享首选项中获取字符串(我已经设置),然后将其输出到字符串数组,以便我的 Image Fetcher 能够读取它(它必须是一个数组供它读取)。
在一项活动中,我正在设置共享首选项:
case R.id.FavouriteWallpaper:
SharedPreferences prefs;
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editor editor = prefs.edit();
editor.putString("imgUrl", mImageUrl);
editor.commit();
}
return super.onOptionsItemSelected(item);
}
在另一个类中,我从共享首选项中获取字符串:
SharedPreferences prefs;
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
prefs.getString("imgUrl", null); //Output imgUrl to String Array somehow
// I would like my image fetcher to read a string array that has been fetched from shared preferences.
mImageFetcher.loadImage(Fragment3.imgUrl[position
- mNumColumns], imageView);
return imageView;
}