android dialog 的item項點擊

//進入界面跳出的dialog樣式

   public void createDialog() {

      builder = newAlertDialog.Builder(Index.this);

      builder.setTitle(R.string._index_submenu_title);

      builder.setItems(new String[] { "啟動照相機", "打開手機相機", "取消選擇" },

            newDialogInterface.OnClickListener() {

                @Override

                public void onClick(DialogInterfacedialog, intwhich) {

                   // TODO Auto-generated method stub

                   //which為從0開始的。為使其也從1開始。

                   switch (which+1) {

                   case IMG_CAMERA:

                      OpenCamera();

                      break;

                   case IMG_FILE:

                      OpenFile();

                      break;

                   case SELECT_CANCEL:

                      break;

                   default:

                      break;

                   }

                }

            });

 

   }

==========================================

dialog點擊按鈕的事件:

public void saveImageDialog(String path) {
ImageView newImage = new ImageView(Index.this);
Bitmap bitmap=MyCommon.fitSizeImg(path,1);
newImage.setImageBitmap(bitmap);
// 顯示對話框
new AlertDialog.Builder(Index.this)
.setTitle("picture")
.setView(newImage)
.setPositiveButton("save",
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
// 把圖片路徑保存到數據庫中
imageDbhelp1.insertlujin(fileName);

finish();
Intent intent3 = new Intent(Index.this,
Index.class);
startActivity(intent3);
}
}).setNegativeButton("cancel", null).show();

}

作者:kankankankan2222

發佈留言