I am developing a dictionary app. I have the following code which show 20 most recent history word.
public List<Bean> getHistoryWords() {
SQLiteDatabase db = initializer.getReadableDatabase();
String sql = "SELECT * FROM " + HISTORY_NAME +
" WHERE " + STATUS + " ORDER BY " + STATUS + " DESC LIMIT 20" ;
Cursor cursor = db.rawQuery(sql, null);
List<Bean> wordList = new ArrayList<Bean>();
while(cursor.moveToNext()) {
int id = cursor.getInt(0);
String english = cursor.getString(1);
String bangla = cursor.getString(2);
String status = cursor.getString(3);
wordList.add(new Bean(id, english, bangla, status));
}
cursor.close();
db.close();
return wordList;
}
I would like to provide an option for user to change the number of history item from LIMIT 20 to LIMIT 50 or LIMIT 100 through Preferences.
I follow this tutorial, but I was stuck in "5) Saving/reading data". I tried to put the SharedPreferences under getHistoryWords, but I got error cannot resolve getBaseContext.
public List<Bean> getHistoryWords() {
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Where should I put the code?
There is a simplest way for it. First, create YourAppName , that extends
ApplicationDeclareContextas static and init it on Application 's onCreate method,declare YourApp in Manifest.xml
android:name="com.yourpackagename.app.YourApp"in application tag,Now, you can get for Context, every where you need like this,
I hope this will help for you.