How can I connect the finished database sqlite in the application. The database contains only one table for 2 fields, id and name. Then, let's say, display the data in a listview or Textview . Maybe there are links to the lessons, and then google something and did not find it. We need the simplest example.

  • Here is a completely informative answer. stackoverflow.com/questions/34880061/… - SomeFire
  • This is a bit wrong, I need to add a database to my developed application and then already in it with a database to carry out manipulations, that is, output data in text or foliage and etc. - Grohovac
  • There is a link to tutorialspoint, which says how to connect sqlite and how to work with it. - SomeFire

1 answer 1

I SQLiteOpenHelper something similar, here's the SQLiteOpenHelper code, checks for the presence of a database with the specified name, if there is none, copies the assets from the base into the application folder.

 private static class DatabaseHelper extends SQLiteOpenHelper { public DatabaseHelper(Context context, String name, int version) throws IOException { super(context, name, null, version); File dbFile = context.getDatabasePath(name); if (!dbFile.exists()) { dbFile.getParentFile().mkdirs(); InputStream is = context.getAssets().open(name); OutputStream os = new FileOutputStream(dbFile); byte[] buffer = new byte[1024]; while (is.read(buffer) > 0) { os.write(buffer); } os.flush(); os.close(); is.close(); } } @Override public void onCreate(SQLiteDatabase db) { } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } }