android - on long click listener delete item in list dialog -
i using dialog show item of list of string code is
final charsequence[] items = {"1", "2", "3"}; alertdialog.builder builder = new alertdialog.builder(activity.this); builder.setitems(items, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int item) { toast.maketext(getapplicationcontext(), items[item], toast.length_short).show(); } }).show();
now question how implement onlongclicklistener method to delete selected item dialog looking shown in image
you need implement onitemlongclick
method follows:
listview.setonitemlongclicklistener(new adapterview.onitemlongclicklistener() { @override public boolean onitemlongclick(adapterview<?> av, view v, int pos, long id) { // todo: position of item clicked. // delete collection eg.arraylist. // call notifydatasetchanged refresh // views displaying updated list. return true; } });
Comments
Post a Comment