|
|
|
Android - สอบถามเกี่ยวกับ startActivityForResult ใน Tab Widget หน่อยคับ |
|
|
|
|
|
|
|
ลองเอา Code มาดูหน่อยครับ
|
|
|
|
|
Date :
2014-01-10 11:44:24 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (Android-Java)
Intent intent3 = new Intent().setClass(this, Class3.class); // เรียกไปหน้าที่แสดงรูป
spec = oth.newTabSpec(tTab3).setIndicator(tTab3) .setContent(intent3);
oth.addTab(spec);
public void displayPict(View v) { // กดปุ่ม Button จะไป Browse รูปในเครื่อง
Intent itn = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult( itn, SELECT_IMAGE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data); // รูปที่คลิกได้จากการ Browse จะต้องมาแสดงใน ImageView
if (requestCode == SELECT_IMAGE && resultCode == RESULT_OK
&& data != null) {
Uri selectedImage = data.getData();
data.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Log.d(TAG, "uri " + selectedImage);
String [] filePathColumn = { MediaStore.Images.Media.DATA };
Log.d(TAG, "filePathcolumn " + filePathColumn);
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
Log.d(TAG, "cursor " + cursor + " col index " + columnIndex);
String pathfile = cursor.getString(columnIndex);
Log.d(TAG, "pic path " + pathfile);
cursor.close();
int width = ImagesView.getWidth();
int height = ImagesView.getHeight();
BitmapFactory.Options factoryOptions = new BitmapFactory.Options();
factoryOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(pathfile, factoryOptions);
int imageWidth = factoryOptions.outWidth;
int imageHeight = factoryOptions.outHeight;
Log.d(TAG, "w h of photo " + imageWidth + "x"+ imageHeight);
int scaleFactor = Math.min(imageWidth/width, imageHeight/height);
Log.d(TAG, "scale " + scaleFactor);
factoryOptions.inJustDecodeBounds = false;
factoryOptions.inSampleSize = scaleFactor;
factoryOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeFile(pathfile,
factoryOptions);
ImagesView.setImageBitmap(bitmap);
}
}
|
|
|
|
|
Date :
2014-01-12 18:46:31 |
By :
Amporn_Aom |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|