2011-10-04 30 views
0

我很難從活動返回信息,我對實現的理解是不完整的。Android加載圖庫onclick,返回圖像位圖

我想要的是用戶能夠點擊一個按鈕來加載android畫廊,選擇一個圖像,該圖像(或圖像鏈接也許)被轉換爲位圖/繪製出現在我的活動UI佈局。 (我知道爲什麼,畫廊應用程序中沒有任何意圖 - 爲了編輯我沒有訪問權限,但我不知道這是什麼意思,但我不知道溶液)

ImageView galleryClick = (ImageView)findViewById(R.id.addgallery); 

    profilePic = (ImageView)findViewById(R.id.profilepic); 

    galleryClick.setOnClickListener(new OnClickListener(){ 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
      intent.setType("image/*"); 

      startActivityForResult(Intent.createChooser(intent, "Select Picture"),1); 

     } 

    }); 

我希望是在onActivityFinished會在我的手寫的活動被調用,但該方法是從來沒有所謂的(我把一個斷點在其代碼

public void onActivityResult(int requestCode, int resultCode, Intent data) { 

    if (resultCode == RESULT_OK) { 

     if (requestCode == 1) { 
      // currImageURI is the global variable I'm using to hold the content:// URI of the image 
      //currImageURI = data.getData(); 
     } 
    } 
} 

解決方案?

+0

斷點不取決於你如何從IDE啓動的應用程序始終尊重。在requestCode == 1塊中拋出一條日誌消息 - 是否顯示? –

回答

1

如果我正確理解你的問題,我相信以前在堆棧溢出時會提出類似的問題。這裏是一個我在想:

Get/pick an image from Android's built-in Gallery app programmatically

+0

但我的onActivityResult函數永遠不會被調用。正如我所提到的那樣,我在那裏放置了一個斷點,它永遠不會在那裏對圖庫中選擇的內容做任何事情 – CQM

+0

嘗試使用'startActivityForResult(Intent.createChooser(intent,「Select Picture」),-1);'而不是'startActivityForResult(Intent.createChooser(intent,「Select Picture」),1);' –

+0

這更貼近我的問題,http://stackoverflow.com/questions/2497205/how-to-return-a-result-startactivityforresult - 從-A-tabhost活動 – CQM