I'm making an android app which displays the list of male and female from database with a user specified age. I almost managed to write the code the below is my code as far as I made
public class UserList{
private ArrayList<String> maleList;
private ArrayList<String> femaleList;} //getter setter for Arraylists
// method to get data
public UserList getUserLists (Context context, String age){
public UserList userList = new UserList();
public ArrayList<String> maleList = new ArrayList<String>();
public ArrayList<String> femaleList = new ArrayList<String>();
db = dbhelper.getWritableDatabase();
Cursor cursor = db.rawQuery(
"select * from USER_INFO where AGE = ?", new String[]{age});
if(cursor != null)
{
if(cursor.moveToFirst())
{
do{
String user_id = cursor.getString(cursor.getColumnIndex("USER_NAME"));
String gender = cursor.getString(cursor.getColumnIndex("GENDER"));
if(gender.equalsIgnorease("MALE"))
maleList.add(user_id);
else
femaleList.add(user_id);
}while(cursor.moveToNext());
cursor.close();
}
}
userList.setMaleList(maleList);
userList.setFemaleList(femaleList);
return userList;
}
But now I need to call this function for getting data from database to cursor in certain intervals like after every 5 minutes. Please help me in doing that the age variale used is age.