3
我得到了我的代碼問題,我想從圖庫中獲取圖像並在我的xml佈局中顯示它(問題是當我點擊按鈕它會去圖庫但當我選擇它只是Gees的另一個選項卡中的圖片)Gallery OnActivityResult在TabActivity中不起作用
1)我的主類創建標籤
public class MainUser extends TabActivit
.....
TabSpec tabSpec10 = mTabHost.newTabSpec("tab_test1");
tabSpec10.setIndicator("Report incident ");
Context ctx10 = this.getApplicationContext();
Intent i10 = new Intent(ctx10, ucrimereport.class);
tabSpec10.setContent(i10);
mTabHost.addTab(tabSpec10);
2)這是我在哪裏製作和調用庫
類public class ucrimereport extends Activity implements OnClickListener,OnItemSelectedListener {
private static final int IMAGE = 1;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.ureport);
.........
gallary = (ImageButton)findViewById(R.id.sdpic_button);
gallary.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// gallary
Intent gallery = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, IMAGE);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK && requestCode==IMAGE){
Uri selectedImage=data.getData();
String path=getPath(selectedImage);
Bitmap bitmapImage=BitmapFactory.decodeFile(path);
//ImageView image=(ImageView)findViewById(R.id.image);
image.setImageBitmap(bitmapImage);
}
}
public String getPath(Uri uri){
String[] filePathColumn={MediaStore.Images.Media.DATA};
Cursor cursor=getContentResolver().query(uri, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex=cursor.getColumnIndex(filePathColumn[0]);
return cursor.getString(columnIndex);
}
像夢一樣工作,你能告訴我如何從相機獲取圖像,即當我打開相機我如何獲得圖像? – ben
試試這個鏈接:http://iamvijayakumar.blogspot.in/2011/08/get-camera-capture-image-path-in.html –