Skip to content

Instantly share code, notes, and snippets.

@mostasim
Last active May 26, 2018 11:25
Show Gist options
  • Save mostasim/06106a28f6106ac3ce598e15e0d5a387 to your computer and use it in GitHub Desktop.
Save mostasim/06106a28f6106ac3ce598e15e0d5a387 to your computer and use it in GitHub Desktop.
public class MyDatabase {
private DatabaseHelper databaseHelper;
private SQLiteDatabase database;
private ArrayList<String> districtList;
public MyDatabase(Context context) {
databaseHelper=new DatabaseHelper(context,"mydb.db");
database=databaseHelper.getReadableDatabase();
}
//Example of getting a list from database
public ArrayList<String> getDistrictList() {
districtList=new ArrayList<>();
String query="SELECT * FROM districtName ";
Cursor cursor=database.rawQuery(query,null);
if (cursor.moveToFirst())
{
do {
districtList.add(cursor.getString(cursor.getColumnIndex("name")));
}while (cursor.moveToNext());
}
return districtList;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment