Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // we first need a database open helper to even touch the DB...
- DatabaseOpenHelper doh = new DatabaseOpenHelper(this);
- // we then get a readable handler to the DB...
- SQLiteDatabase db = doh.getReadableDatabase();
- // then we run a raw SQL query which returns a cursor pointing to the results
- Cursor cursor = db.rawQuery("SELECT * FROM entries", null);
- // number of rows in the result set
- int numOfRows = cursor.getCount();
- final String [] favCountries = new String[numOfRows]; // titles of the blog entries
- cursor.moveToFirst();
- int columnIndex = cursor.getColumnIndex("item");
- for(int i = 0; i < numOfRows; i++) {
- favCountries[i] = cursor.getString(columnIndex);
- cursor.moveToNext();
- Log.d("Country ", favCountries[i]);
- }
- cursor.close();
- String favouriteCountries = "";
- for(int i = 0; i < numOfRows; i++) {
- String current = favCountries[i].toString();
- favouriteCountries = favouriteCountries + current;
- if(i < numOfRows - 1)
- {
- favouriteCountries = favouriteCountries + ", ";
- }
- }
- TextView lblFavCountries = (TextView)findViewById(R.id.lblFavCountries);
- lblFavCountries.setText(favouriteCountries);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement