我想打開一個 dialog box,然後給出兩個選項:
1- 從SD Card中選擇文件 2- 從相機中生成快照
我使用的下面的代碼:
receipt.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(RECEIPT_DIALOG_ID);
}
});
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
AlertDialog.Builder builder = new Builder(this);
case RECEIPT_DIALOG_ID:
builder.setTitle("Choose your file");
dialog = builder.create();
return dialog;
}
那麼如何添加這兩個選項卡呢?
使用下面的代碼,可以提供兩個選項卡:
final CharSequence[] items = {"Camera", "Memory Card"};
builder.setTitle(R.string.pic_option);
builder.setIcon(R.drawable.camera_icon);
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
launchCamera(item);
}
});
builder.create();
builder.show();
Fuction launchCamera(item) :
public void launchCamera(int id){
switch (id) {
case 0:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
((Activity)getParent()).startActivityForResult(cameraIntent, 1888);
break;
case 1:
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
((Activity)getParent()).startActivityForResult(intent, 2);
break;
default:
break;
}
}