我正在使用Xamarin Android。在当前活动中,我有一个编辑表单,而在单击按钮时,我在当前活动中有一个更新查询。
private void OnclickSaveDATAButton(object sender, EventArgs e)
{
var CNICCARDNUMBER = Intent.Extras.GetString("NIC");
var conn = Connection();
conn.BeginTransaction();
var hf = conn.Table<mof>();
var search = hf.Where(x => x.CNICNO == CNICCARDNUMBER).ToList().FirstOrDefault(); //Linq Query
var Hofid = Convert.ToString(search.HOFID);
var data = conn.Query<hof>("UPDATE hof SET HOFNAME = ? WHERE HOFID = ?", Name.Text, Hofid);
conn.Commit();
if (data!= null)
{
Toast.MakeText(this,"Updated Successfully", ToastLength.Short).Show();
}
else
{
Toast.MakeText(this, "Update failed", ToastLength.Short).Show();
}
}
当我返回上一步按钮事件时的活动
public override void OnBackPressed()
{
Intent intent = new Intent(this, typeof(SearchingActivity));
intent.SetFlags(ActivityFlags.ClearTop);
StartActivity(intent);
}
在上一个活动中,我对选项卡选择事件进行了选择查询。当我选择选项卡时,我想刷新ListView并显示更新的数据,而不是旧的数据。
else if (CurrentTab.Position == 1)
{
Gridd = (ListView)FindViewById(Resource.Id.gridview);
Gridd.Visibility = ViewStates.Visible;
var CNICCARDNUMBER = Intent.Extras.GetString("cnic");
var conn = Connection();
var Hofid = 2;
data1 = new List<string>();
var data = conn.Query<combine>("SELECT hof WHERE hof.HOFID=?", Hofid);
foreach (var values in data)
{
data1.Add("CNIC:" + Convert.ToString(values.CNICNO));
data1.Add("Health card Number:" + Convert.ToString(values.CARDNO));
}
Gridd = (Listview)FindViewById(Resource.Id.gridview);
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, data1);
if (data1.Count() > 0)
{
Gridd.SetAdapter(adapter);
// Gridd.Adapter = adapter;
Gridd.ItemClick += Gridd_ItemClick;
}
else
{
Toast.MakeText(this, "No Data returned.", ToastLength.Short).Show();
}
}
问::如何实现?
答案 0 :(得分:0)
您可以从数据库获取新数据,然后在上一个活动的onResume()方法中调用listviewAdapter.OnNotifyPropertyChanged()。 那会刷新您的列表。