Code example for AlertDialog.Builder

Methods: create, setItems

0
			ItemLayoutMain.setOnLongClickListener(new OnLongClickListener() {
				 
				public boolean onLongClick(View arg) {
					//CharSequence[] content={"此商品全螢幕","修改商品資訊","刪除此商品"}; 
					CharSequence[] content={"刪除此商品"};
					Builder MyAlertDialog = new AlertDialog.Builder(context);
					MyAlertDialog.setTitle("商品選單");
					MyAlertDialog.setItems(content, new DialogInterface.OnClickListener() {
						 
						public void onClick(DialogInterface dialog, int which) {
							Intent intent = new Intent();
							Bundle bundle=new Bundle();
							String ID=item_list.get(WhichItem).get("ID");
							switch(which)
							{	 
								/* 
								case 0: 
									intent.setClass(context, itemfullscreen.class); 
									bundle.putString("SerialNumbers",ManageActivity.SerialNumbers); 
									bundle.putString("ID",ID); 
									intent.putExtras(bundle); 
									context.startActivity(intent); 
									break; 
								case 1: 
									intent.setClass(context, edititem.class); 
									bundle.putString("SerialNumbers",ManageActivity.SerialNumbers); 
									bundle.putString("ID",ID); 
									intent.putExtras(bundle); 
									context.startActivity(intent); 
									break; 
									*/ 
								case 0: 
									ManageActivity.ImplementItem delete_item_runnable=new ManageActivity.ImplementItem();
									delete_item_runnable.setdata(1,WhichItem);
									Thread delete_item_thread=new Thread(delete_item_runnable);
									delete_item_thread.start();
									break;	 
								case 1: 
									ManageActivity.ImplementItem FullScreen=new ManageActivity.ImplementItem();
									FullScreen.setdata(3, WhichItem);
									Thread fullScreenThread=new Thread(FullScreen);
									fullScreenThread.start();
									break; 
							} 
							 
						} 
					}); 
					 AlertDialog alert = MyAlertDialog.create();
					 alert.show();
					 
					  
					return false; 
				}