【发布时间】:2013-12-16 13:16:03
【问题描述】:
我在我的适配器中使用 sharedpreferences,但我没有获取默认值 -1,而是将 0 作为默认值。谁能告诉我为什么会这样?
这是我的代码:
//constructor
public PlaylistAdapter(Activity a, ArrayList<Songs> songs) {
activity = a;
data = songs;
prefs = a.getSharedPreferences("com.myapp",
Context.MODE_PRIVATE);
db = new DatabaseHelper(a);
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public View getView(final int position, View convertView,
final ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.song_item, parent, false);
int playpos = prefs.getInt("posPlaying", -1);
//logs 0 as prefsvalue(should be -1) and the position
Log.v("--", prefs.getInt("posPlaying", -1) + " " + position);
}
【问题讨论】:
标签: java android sharedpreferences android-preferences android-adapter