Onメソッドを作成します。Androidスタジオsqlite to listview
db = openOrCreateDatabase("messages", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS message(msg TEXT);");
db.execSQL("INSERT INTO message values('example');");
listeview1 = (ListView) findViewById(R.id.listview);
ArrayList<String> dbArray = myArrayListTodatabase();
ListAdapter mylistadapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, dbArray);
listview.setAdapter(mylistadapter);
myarraististodatabase code;
public ArrayList<String> myArrayListTodatabase() {
db = openOrCreateDatabase("messages", MODE_PRIVATE, null);
db.rawQuery("Select * from message", null);
Cursor c = db.rawQuery("Select * from message", null);
c.moveToFirst();
String dbString = "";
while (!c.isAfterLast()) {
if (c.getString(c.getColumnIndex("msg")) != null) {
dbString += c.getString(c.getColumnIndex("msg"));
dbString += "\n";
}
c.moveToNext();
}
db.close();
return myArraylist;
}
グローバル変数
SQLiteDatabase db = null;
public ArrayList<String> myArraylist = new ArrayList<String>();
イムこれらを使用しますが、私はアプリ