if the posplaying does not hold any value then only the default value will come.so i think posplaying is holding the value as 0.check whether you intiated this value with 0 or some other calculations making this posplaying as 0.
SharedPreferences default value
-
02-09-2022 - |
Question
Im using sharedpreferences in my adapter, but instead of getting the default values -1
im getting 0
as default value. Can anyone tell me why is this happening?
Here is my code:
//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);
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow