如何从列表视图中删除选定的项目?
对于这种混乱,我们深表歉意: 更新的问题: 我正在尝试从列表视图中删除列表项。单击该项目时,将显示警报对话框。如果我单击“确定”,则必须从列表视图中删除所选项目。 我的代码如下:
case R.id.lvinc:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Delete Event ");
builder.setMessage("Delete this Event ?");
builder.setPositiveButton("Ok, Delete",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
try
{
???? //What code to delete the selected list item?
}catch(Exception e)
{
e.printStackTrace();
}
}
});
AlertDialog alert = builder.create();
alert.show();
displaylist();
break;
非常感谢任何帮助,并提前致谢......
SORRY FOR THIS CONFUSION:
UPDATED QUESTION:
I'm trying to remove a list item from the listview. when the item is clicked, the alertdialog is shown. If i click OK, then the selected item must be removed from the listview.
My Code goes below:
case R.id.lvinc:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Delete Event ");
builder.setMessage("Delete this Event ?");
builder.setPositiveButton("Ok, Delete",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
try
{
???? //What code to delete the selected list item?
}catch(Exception e)
{
e.printStackTrace();
}
}
});
AlertDialog alert = builder.create();
alert.show();
displaylist();
break;
Any help is really appreciated and thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我尝试解决它并得到了一个解决方案,请执行以下代码:
listview.java
//Adapter Class
ListAdapter.java
I tried to solve it and got one solution pls go through the code below:
listview.java
//Adapter Class
ListAdapter.java
我不知道你用的是什么类型的数据。
我想象游标、数据库或列表,请随时告诉我们,这样会更容易提供帮助。
此示例适用于列表:
I don't know what kind of data you are using.
I imagine Cursor, database or List, feel free to tell us, so it will be easier to help.
This example is for a list:
您可能有某种适配器,可以提供某种数据。
从该列表中删除该项目,然后将 DataChanged 通知给 ListView。
最后:dialog.dismiss();
You propably have some kind of Adapter, that you have feed with some kind of data.
Remove the item from that list, and notifyDataChanged to the ListView.
And finally: dialog.dismiss();
否则放置 tab_unselected 图像。
otherwise put tab_unselected image.