Android 更新数据库sqlite后更新listview

Android 更新数据库sqlite后更新listview,android,Android,如何在更新数据库sqlite上的行后更新listview中的项。我已将notifyDataSetChanged()放入行中,但未成功,没有错误,但未刷新行中的数据。如果我单击“上一步菜单”并再次打开列表,数据将更改。所以我想在更新数据之后更新第行中的数据。下面是我的代码,谢谢 CustomBaseAdapter adapter; ListView cListView; 在onCreate中: cListView = (ListView) findViewById(R.id.list_categ

如何在更新数据库sqlite上的行后更新listview中的项。我已将notifyDataSetChanged()放入行中,但未成功,没有错误,但未刷新行中的数据。如果我单击“上一步菜单”并再次打开列表,数据将更改。所以我想在更新数据之后更新第行中的数据。下面是我的代码,谢谢

CustomBaseAdapter adapter;
ListView cListView;
在onCreate中:

cListView = (ListView) findViewById(R.id.list_category);
List<ItemsArtikel> rowItems = (List<ItemsArtikel>) db.getAllCategory(katname);
adapter = new CustomBaseAdapter(this, rowItems);
cListView.setAdapter(adapter);
调用时,它只会通知register视图更新内容以反映更改

在本例中,您正在更新数据库中的数据,而不是适配器数据模型中的数据。要反映
列表视图中的更改
,您需要更新
适配器的
数据模型,然后调用notifyDataSetChanged()


如果您直接从数据库呈现数据,请使用并实现
onContentChanged()
更新ListView

在添加适配器之前使用以下行

@Override
protected void onPostExecute(HashMap<String, Object> result) {
    String id = (String) result.get("id");
    String path = (String) result.get("image");

    // update row in database
    db.updateRowCategory(id, path);
    cListView.Invalidate();
    cListView.setAdapter(adapter);
    cListView.Invalidate();
    adapter.notifyDataSetChanged();
}
@覆盖
受保护的void onPostExecute(HashMap结果){
stringid=(String)result.get(“id”);
字符串路径=(字符串)result.get(“图像”);
//更新数据库中的行
db.updateRowCategory(id,路径);
cListView.Invalidate();
setAdapter(适配器);
cListView.Invalidate();
adapter.notifyDataSetChanged();
}

Hello Animesh,谢谢回复。我已经更新了我的帖子,如果我可以使用上面的查询,那么如何使用onContentChanged()。在哪里之前?你能把我的密码复制到你的答案上吗,谢谢
@Override
protected void onPostExecute(HashMap<String, Object> result) {
    String id = (String) result.get("id");
    String path = (String) result.get("image");

    // update row in database
    db.updateRowCategory(id, path);

    cListView.setAdapter(adapter);
    adapter.notifyDataSetChanged();
}
@Override
protected void onPostExecute(HashMap<String, Object> result) {
    String id = (String) result.get("id");
    String path = (String) result.get("image");

    // update row in database
    db.updateRowCategory(id, path);
    cListView.Invalidate();
    cListView.setAdapter(adapter);
    cListView.Invalidate();
    adapter.notifyDataSetChanged();
}