SharedPreferences.Editor editor = getSharedPreferences("identifier",
MODE_PRIVATE).edit();
//identifier is the unique to fetch data from your SharedPreference.
editor.putInt("keyword", 0);
// saved value place with 0.
//use this "keyword" to fetch saved value again.
editor.commit();//important line without this line your value is not stored in preference
// fetch the stored data using ....
SharedPreferences prefs = getSharedPreferences("identifier", MODE_PRIVATE);
// here both identifier will same
int fetchvalue = prefs.getInt("keyword", 0);
// here keyword will same as used above.
// 0 is default value when you nothing save in preference that time fetch value is 0.
вам нужно использовать SharedPreferences в AdapterClass или любом другом. в этот раз просто используйте это объявление и используйте ту же самую задницу выше.
SharedPreferences.Editor editor = context.getSharedPreferences("idetifier",
Context.MODE_PRIVATE).edit();
SharedPreferences prefs = context.getSharedPreferences("identifier", Context.MODE_PRIVATE);
//here context is your application context
для строкового или логического значения
editor.putString("stringkeyword", "your string");
editor.putBoolean("booleankeyword","your boolean value");
editor.commit();
извлекают данные так же, как указано выше
String fetchvalue = prefs.getString("keyword", "");
Boolean fetchvalue = prefs.getBoolean("keyword", "");