2 hcg 21 hcg_21 于 2013.03.06 11:27 提问

点击 item 时不显示 alertdialouge

我想实现点击 pdfimage 时显示 alert dialogue 的功能。我用的下面的代码但还是没有显示 alertdialogue,请大家点评一二。

private OnItemClickListener itemClickListener=new OnItemClickListener() {
  @SuppressWarnings("rawtypes")
  public void onItemClick(AdapterView parent, View arg1, int position, long arg3) {
      int i=position;
      pdf=pdfarray[i];
 /*******************************/
  AlertDialog.Builder builder = new AlertDialog.Builder(ImageShowActivity.this);
    final AlertDialog alert = builder.create();
    builder.setMessage("Are you sure you want to exit?")
       .setNeutralButton("Cancel",new DialogInterface.OnClickListener(){
       public void onClick(DialogInterface dialog, int id) {
            alert.dismiss();   
           }
        })
       .setPositiveButton("Download", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
           Intent intent=new Intent(ImageShowActivity.this,OpenPDFNew.class);
           intent.putExtra("pdfurl",pdf );
           startActivity(intent);
           }
       })
      .setNegativeButton("Online", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
           }
   });
    alert.show();
/****************************************/
 }
};

1个回答

nana4ever
nana4ever   2013.03.06 14:43

你在申明 alert Builder 的内容前,调用 builder.create()。
创建内容后,你应该用下面的代码调用 builder.create()

AlertDialog.Builder builder = new AlertDialog.Builder(Activity_name.this);
        builder.setItems(items, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int position) {
                .........
                }
            }
        });
        builder.create().show();
Csdn user default icon
上传中...
上传图片
插入图片