我想从列表视图中删除记录。所以我使用长按。如果用户输入yes,则必须长按一个对话框,然后删除该记录。如果用户按下否按钮则关闭。 deleterecord
方法正在执行但未执行任何操作。
public class ListActivity : Activity
{
ListView listItems;
protected override void OnCreate (Bundle SaveInstace)
{
base.OnCreate (SaveInstace);
SetContentView (Resource.Layout.Listviewlayout);
//back button
ActionBar.SetDisplayHomeAsUpEnabled (true);
//Gets ListView object instance
Database sqldb1 = ((GlobalClass)this.Application).sqldb;
listItems = FindViewById<ListView> (Resource.Id.listView1);
GetCursorView ();
//Add ItemClick event handler to ListView instance
listItems.ItemClick += new EventHandler<AdapterView.ItemClickEventArgs> (item_Clicked);
listItems.ItemLongClick+= new EventHandler<AdapterView.ItemLongClickEventArgs> (item_longclicked);
}
my item_clicked
方法就在这里..
public void item_longclicked(object sender,AdapterView.ItemLongClickEventArgs e)
{
Database sqldb1 = ((GlobalClass)this.Application).sqldb;
TextView shName = e.View.FindViewById<TextView> (Resource.Id.Name_row);
TextView shLastName = e.View.FindViewById<TextView> (Resource.Id.LastName_row);
TextView shAge = e.View.FindViewById<TextView> (Resource.Id.Age_row);
int s=e.Position;
AlertDialog.Builder alert = new AlertDialog.Builder (this);
alert.SetTitle ("Do you want to delete");
alert.SetPositiveButton ("yes", (EventHandler<DialogClickEventArgs>)null);
alert.SetNegativeButton ("No", (EventHandler<DialogClickEventArgs>)null);
var dial = alert.Create ();
dial.Show ();
//get the buttons
var yesbtn= dial.GetButton((int)DialogButtonType.Positive);
var nobtn = dial.GetButton ((int)DialogButtonType.Negative);
yesbtn.Click+=delegate
{
sqldb1.DeleteRecord(s);
GetCursorView();
};
}