Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android dialog 的item項點擊

android dialog 的item項點擊

編輯:關於Android編程

//進入界面跳出的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
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved