Search code examples
androidandroid-layoutandroid-activityonactivityresult

How to add another layout to display in OnActivityResult()?


I have an app that has a user take a picture and have it uploaded to a website.

I have this code right now:

@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"));
            }
        }
    }

However, before the image is downloaded, I want to add a layout that brings up a Spinner (drop down menu) with a list of items that a user can choose from to describe the picture.

What should I add to the code so that before the picture is uploaded, a new layout is displayed, a user makes a selection and hits the OK button on that layout, and then returns back to this piece of code to continue the upload process?


Solution

  • 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;
    }