Last active
May 26, 2018 11:25
-
-
Save mostasim/06106a28f6106ac3ce598e15e0d5a387 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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