android开发中如何使用 alertDialog从listView中删除数据?

我现在使用listView展示了很多的配置信息,我现在想在点击其中一条的时候填出 alertDialog,点击确认后就删除该条数据,( ArrayAdapter ,ArrayList,listView 全部删除),我知道在 下面的onItemLongClick 方法中 参数 arg2  是选中的序号,但是我不知道如何继续处理下去

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
listview.setOnItemLongClickListener( new AdapterView.OnItemLongClickListener() {
 
public boolean onItemLongClick(AdapterView<!--?--> arg0, View arg1, int arg2, long arg3) {
         AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
          builder.setCancelable( true );
          builder.setTitle( "Vuoi davvero cancellare il profilo?" );
          builder.setPositiveButton( "Si" , new DialogInterface.OnClickListener() {
                             public void onClick(DialogInterface dialog, int which) {
                                            // How to remove the selected item?
                              }
                         });
 
builder.setNegativeButton( "Annulla" , new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int which) {
         }
         });
         AlertDialog alert = builder.create();
  
         alert.show();
  
         profilesAdapter.notifyDataSetChanged();
 
 
 
 
     return true ;
  
     }
  
     });

处理方法

 

试下这个
设置  ListaUtentiStringa ArrayList、 profilesAdapter adapter 为全局变量

1
2
3
4
5
6
7
8
builder.setPositiveButton( "Si" , new DialogInterface.OnClickListener() {
                         public void onClick(DialogInterface dialog, int which) {
                                        // How to remove the selected item?
                               ListaUtentiStringa.remove(arg2);
                                  profilesAdapter.notifyDataSetChanged();
                                  dialog.dismiss();
                          }
                     });

 


原文地址:http://www.itmmd.com/201411/125.html 
该文章由 萌萌的IT人 整理发布,转载须标明出处。

你可能感兴趣的:(android)