如何添加另一个布局以在OnActivityResult()中显示?

时间:2011-09-23 14:34:45

标签: android android-layout android-activity onactivityresult

我有一个应用程序让用户拍照并将其上传到网站。

我现在有这个代码:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == CAMERA_PIC_REQUESTED) {
            if(resultCode == RESULT_OK) {   
                // Maybe add the additional code here?          

                picture = convertImageUriToFile(imageUri, this);


                Thread thread = new Thread(null, uploader, "MagentoBackground");
                thread.start();
                m_ProgressDialog = ProgressDialog.show(pictures.this, "Please wait...", "Uploading data ...", true, true);

            }
        } else if (requestCode == EXPERIMENT_CODE) {
            if (resultCode == Activity.RESULT_OK) {
                experimentInput.setText("" + data.getExtras().getInt("edu.cs.h.exp_id"));
            }
        }
    }

但是,在下载图像之前,我想添加一个布局,调出一个Spinner(下拉菜单),其中包含一个用户可以选择的项目列表来描述图片。

我应该在代码中添加什么内容,以便在上传图片之前显示新的布局,用户进行选择并点击该布局上的 OK 按钮,然后返回这段代码继续上传过程?

1 个答案:

答案 0 :(得分:2)

static final int _MY_DIALOG_ = 11;

if(resultCode == RESULT_OK) {   
    showDialog(_MY_DIALOG_);
}

@Override
protected Dialog onCreateDialog(int id) {
    if(id==_MY_DIALOG_){
        CharSequence[] shush = new CharSequence[10];
        //initialize shush
        Dialog dialog = new AlertDialog.Builder(this).setTitle("Select Animation")
            .setSingleChoiceItems(shush, 0,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    //the user has selected which!!!
                    dialog.dismiss();
                }
            }).create();
        dialog.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface arg0) {
                //do what you want now since the user selected!
                picture = convertImageUriToFile(imageUri, this);
                Thread thread = new Thread(null, uploader, "MagentoBackground");
                thread.start();
                m_ProgressDialog = ProgressDialog.show(pictures.this, "Please wait...", "Uploading data ...", true, true);
            }
        });
        return dialog;
    }
    return null;
}