我已经使用sqflite插件快速创建了数据库。我在android native中为我的应用创建了android主屏幕小部件。现在,我需要从SQLite获取数据。那就是我试图使用Android Native sqflite Package从SQLite数据库中获取数据。有可能吗?
答案 0 :(得分:2)
请参阅此post:
List<String> r = new ArrayList<String>();
这属于onCreate
类:
new LongOperation().execute("");
然后您可以创建一个新类:
private class LongOperation extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
connect();
return "Executed";
}
@Override
protected void onPostExecute(String result) {
ArrayAdapter<String>adapter=new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1,r);
ListView list=(ListView)findViewById(R.id.listView1);
list.setAdapter(adapter);
}
@Override
protected void onPreExecute() {}
@Override
protected void onProgressUpdate(Void... values) {}
}
答案 1 :(得分:0)
>波动没有限制
Sqlite的基本规则,您需要记住
private fun accessDB(){
try {
GlobalScope.launch {
var db:SQLiteDatabase = SQLiteDatabase.openDatabase(getDatabasePath("epistle.db").absolutePath,null,SQLiteDatabase.OPEN_READWRITE);
Log.d(MainActivity::class.java.name , "Database Path "+db.path.toString())
Log.d("" , "Database version "+db.version.toString())
var cursor = db.query("userInfo",null,null,null,null,null,null)
cursor?.let {
while (cursor.moveToNext()){
var columnNames =cursor.columnNames
columnNames.forEach {
Log.d(
MainActivity::class.java.name,
"$it "+cursor.getString(cursor.getColumnIndex(it))
)
}
}
}
}
}catch (e:Exception){
e.printStackTrace();
}
}
MainActivity: Database Path /data/u
MainActivity: id 1
MainActivity: uid XfXCx613bKWl0EuDU
MainActivity: username Lee And May
MainActivity: email yepi1@yep.com
MainActivity: location US
MainActivity: isBiometricEnabled 0
MainActivity: isNotificationsEnable
MainActivity: morning 152.549
MainActivity: evening 166.529
MainActivity: plan Basic
MainActivity: lattitude 0
MainActivity: lognitude 0
MainActivity: userID XfXCx613bKWl0E
MainActivity: theme 2
MainActivity: premiumStartDate null
MainActivity: premiumEndDate null
MainActivity: isPremium 0