0

我有一个添加联系人应用程序,它在某些部分显示已注册的联系人,因此当您单击它时,它会显示(姓名和电话号码)和一个确定按钮,所以我想添加一个删除按钮来删除它的值(删除来自数据库的联系人值)来自对话框。以下是代码:

联系人的 ListView:

   ListView user = (ListView) findViewById(R.id.lvShowContatos);
    //String = simple value ||| String[] = multiple values/columns
    String[] campos = new String[] {"nome", "telefone"};

    list = new ArrayList<String>();
    c = db.query( "contatos", campos, null, null, null, null, null);
    c.moveToFirst();
    String lista = "";
    if(c.getCount() > 0) {
        while(true) {
           list.add(c.getString(c.getColumnIndex("nome")).toString());
            if(!c.moveToNext()) break;
        }
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, list);

    user.setAdapter(adapter);

    user.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            c.moveToPosition(position);
            String nome = c.getString(c.getColumnIndex("nome"));
            String telefone = c.getString(c.getColumnIndex("telefone"));
            ShowMessage(nome, telefone);
        }
    });

还有“ShowMessage”代码,它是显示的对话框:

       public void ShowMessage(String titulo,String msg){
    AlertDialog.Builder dialogo = new AlertDialog.Builder(this);        
    dialogo.setMessage(msg);        
    dialogo.setTitle(titulo);
    dialogo.setNeutralButton("OK", null);       
    dialogo.show();
}
4

2 回答 2

2
dialogo.setNegativeButton("Delete", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                    //delete contact or what you want.
               }
           });

或在您的代码上:

dialogo.setNegativeButton("Delete", null);

阅读更多关于http://developer.android.com/guide/topics/ui/dialogs.html

于 2012-09-19T17:50:04.240 回答
0

您必须使用此处文档中所述的自定义对话框

http://developer.android.com/guide/topics/ui/dialogs.html

于 2012-09-19T17:50:49.930 回答