我已经读过,sqlitedb中的更新响应更改需要内容提供程序。我已经使用sqliteonehelper类进行了应用程序,其中我已经编写了所有查询现在我需要创建响应式UI,只要在sqlite db UI中进行更改需要使用更新值更新我已经读过我可以使用Loader类完成但是它需要内容提供者我是这么认为但我不喜欢我的应用程序的用户提供商如何实现没有提供商让我告诉你到目前为止我有什么:
这是我编写查询的sqliteonehelper类:
public void InsertorUpdate(Model_Account modlobj){
SQLiteDatabase db=this.getReadableDatabase();
String query=" SELECT * FROM " + Model_Account.Accunt_Table+ " WHERE " + Model_Account.Account_ID + " =" + modlobj.getAccountID() +"";
Cursor c = db.rawQuery(query, null);
if (c.moveToFirst()) {
Update(modlobj);
} else {
onInsert(modlobj);
}db.close();
}
这是我在我的活动中实施的
JsonObjectRequest jsonObjRequest = new JsonObjectRequest(Request.Method.GET, params[0], new JSONObject(),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
String server_response = response.toString();
try {
JSONObject json_object = new JSONObject(server_response);
JSONArray json_array = new JSONArray(json_object.getString("AccountPageLoadAccountListResult"));
for (int i = 0; i < json_array.length(); i++) {
Model_Account modelobjs = new Model_Account();
JSONObject json_arrayJSONObject = json_array.getJSONObject(i);
modelobjs.setCompany_group(json_arrayJSONObject.getString("CompanyName"));
modelobjs.setState(json_arrayJSONObject.getString("Region"));
modelobjs.setAccountID(json_arrayJSONObject.getInt("AccountID"));
account_sf_db.InsertorUpdate(modelobjs);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getBaseContext(), error.toString(), Toast.LENGTH_SHORT).show();
}
});
queue.add(jsonObjRequest);
在sqliteonehelper类中列出:
public List<Model_Account> list() {
String countQuery = "SELECT * FROM " + Model_Account.Accunt_Table;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
List<Model_Account> listobj = new ArrayList<Model_Account>();
if(cursor!=null && cursor.getCount()>0) {
if (cursor.moveToFirst()) {
do {
Model_Account modelobj = new Model_Account();
modelobj.setID(cursor.getInt(cursor.getColumnIndex(Model_Account.id)));
modelobj.setCompany_group(cursor.getString(cursor.getColumnIndex(Model_Account.company_groups)));
modelobj.setState(cursor.getString(cursor.getColumnIndex(Model_Account.State)));
listobj.add(modelobj);
} while (cursor.moveToNext());
}
}
return listobj;
这是我在活动中为我的recyclerview设置适配器的地方:
listobj = account_sf_db.list();
accountListAdapter = new AccountListAdapter(listobj, getApplicationContext());
recyclerView.setAdapter(accountListAdapter);
我有点困惑从哪里开始可以任何人帮助我们提前谢谢!!