2011-09-23 48 views
0

我有一個應用程序,讓用戶拍照並將其上傳到網站。添加另一個佈局以顯示在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")); 
      } 
     } 
    } 

然而,在下載圖像之前,我想補充一點,與用戶的項目清單帶來了一個微調(下拉菜單)佈局可以選擇來描述圖片。

我應該添加什麼代碼,以便在上傳圖片之前顯示一個新的佈局,用戶做出選擇並點擊該佈局上的「確定」按鈕,然後返回到這段代碼繼續上傳過程?

回答

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; 
} 
+0

這看起來不錯!但是,我不知道應該在哪裏添加這個/我應該從原始代碼中提取哪些內容。你介意編輯一下我原來的帖子,告訴我應該在哪裏實現它?我自己嘗試過,但我得到了一些錯誤!我爲此成爲新手道歉。 – Mxyk

+0

你的'if(resultCode == RESULT_OK){ showDialog(_MY_DIALOG_) }'應該更新爲看起來像我給你..你必須添加靜態整數和函數onCreateDialog到你的活動 –

+0

我有一個錯誤。在圖片類型的convertImageUriToFile(Uri,Activity)方法不適用於參數(Uri,new DialogInterface.OnDismissListener(){}) ; – Mxyk

相關問題