如何使用新数据更新listview(C#android sqlite) [英] How to update listview wih new data (C# android sqlite)
问题描述
我使用sqlite表创建了一个应用程序。
通过查询所有数据或特定值,将sqlite表加载到带有多列的listview中。
on cklik在listview中的一行中,它会打开新的活动来编辑数据。
新数据正确保存在sqlite表上。
我无法刷新视图仅用于行/列我有变化,但只能通过再次查询适配器。
有没有办法做到这一点?
什么我试过了:
protected override void OnActivityResult(int requestCode,Result resultCode,Intent data)
{
base.OnActivityResult(requestCode,resultCode,data);
if(resultCode == Result.Ok)
{
int IdReturned = Convert.ToInt32(data.GetStringExtra(Id_Ret));
int ValueReturned = Convert.ToInt32(data.GetStringExtra(CurMtr_Ret));
int ListidReturned = Convert.ToInt32(data.GetStringExtra(Listid));
db.UpdateRec(IdReturned,ValueReturned,1);
ICursor Rcursor =( ICursor)listView.GetItemAtPosition(ListidReturned);
db_cursor = db.FindSingleRec(IdReturned);
listView.Adapter =(IListAdapter)new MtrCursorAdapter(this,db_cursor,true) ;
((BaseAdapter)listView.Adapter).NotifyDataSetChanged();
}
}
I have make a app using sqlite table.
The sqlite table is loaded into listview with multicolumns either by quering all of data or for specific values.
On cklik of a row in listview , it opens new activity to edit data.
The new data are saved on sqlite table correctly.
I can't refresh the view only for the row/column i have change but only by quering again the adapter.
Is there a way to do that?
What I have tried:
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (resultCode == Result.Ok)
{
int IdReturned = Convert.ToInt32(data.GetStringExtra("Id_Ret"));
int ValueReturned = Convert.ToInt32(data.GetStringExtra("CurMtr_Ret"));
int ListidReturned = Convert.ToInt32(data.GetStringExtra("Listid"));
db.UpdateRec(IdReturned, ValueReturned, 1);
ICursor Rcursor = (ICursor)listView.GetItemAtPosition(ListidReturned);
db_cursor = db.FindSingleRec(IdReturned);
listView.Adapter = (IListAdapter)new MtrCursorAdapter(this, db_cursor, true);
((BaseAdapter)listView.Adapter).NotifyDataSetChanged();
}
}
推荐答案
您需要通知视图数据已更改并需要刷新视图。请参阅如何在Android中正确实施BaseAdapter.notifyDataSetChanged() [ ^ ]。
You need to notify the view that the data has changed and needs the view to be refreshed. See How to correctly implement BaseAdapter.notifyDataSetChanged() in Android[^].
这篇关于如何使用新数据更新listview(C#android sqlite)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!