Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1.  // we first need a database open helper to even touch the DB...
  2.         DatabaseOpenHelper doh = new DatabaseOpenHelper(this);
  3.         // we then get a readable handler to the DB...
  4.         SQLiteDatabase db = doh.getReadableDatabase();
  5.         // then we run a raw SQL query which returns a cursor pointing to the results
  6.         Cursor cursor = db.rawQuery("SELECT * FROM entries", null);
  7.         // number of rows in the result set
  8.         int numOfRows = cursor.getCount();
  9.         final String [] favCountries = new String[numOfRows]; // titles of the blog entries
  10.  
  11.         cursor.moveToFirst();
  12.         int columnIndex = cursor.getColumnIndex("item");
  13.         for(int i = 0; i < numOfRows; i++) {
  14.             favCountries[i] = cursor.getString(columnIndex);
  15.             cursor.moveToNext();
  16.             Log.d("Country ", favCountries[i]);
  17.         }
  18.         cursor.close();
  19.  
  20.         String favouriteCountries = "";
  21.         for(int i = 0; i < numOfRows; i++) {
  22.  
  23.            String current = favCountries[i].toString();
  24.             favouriteCountries = favouriteCountries + current;
  25.             if(i < numOfRows - 1)
  26.             {
  27.                 favouriteCountries = favouriteCountries + ", ";
  28.             }
  29.         }
  30.  
  31.         TextView lblFavCountries = (TextView)findViewById(R.id.lblFavCountries);
  32.         lblFavCountries.setText(favouriteCountries);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement