2013-07-25 1 views
0

안녕하세요, 1 개의 액티비티에서 2 개의 이미지를로드하려는 경우 button1을 클릭하면 이미지를로드하고 ImageView 1에 이미지를 설정하고 버튼 2를 클릭하면로드 할 수 있습니다 imagview2로 설정할 수없는 이유는 무엇입니까? 내가 잘못하고있는 곳?안드로이드 - 1 액티비티에 이미지 2 개로드

잘못

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    overridePendingTransition(R.anim.push_left_in, R.anim.hold); 
    setContentView(R.layout.compare); 

    ImageButton imgBtnCpr1 = (ImageButton) findViewById(R.id.imgBtnCpr1); 

    imgBtnCpr1.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      Intent i = new Intent(
        Intent.ACTION_PICK, 
        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 

      startActivityForResult(i, RESULT_LOAD_IMAGE1); 

     } 
    }); 

    ImageButton imgBtnCpr2 = (ImageButton) findViewById(R.id.imgBtnCpr2); 

    imgBtnCpr2.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      Intent t = new Intent(
        Intent.ACTION_PICK, 
        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 

      startActivityForResult(t, RESULT_LOAD_IMAGE2); 
     } 
    }); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    if (requestCode == RESULT_LOAD_IMAGE1 && resultCode == RESULT_OK 
      && null != data) { 
     Uri selectedImage = data.getData(); 
     String[] filePathColumn = { MediaStore.Images.Media.DATA }; 

     Cursor cursor = getContentResolver().query(selectedImage, 
       filePathColumn, null, null, null); 
     cursor.moveToFirst(); 

     int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
     String picturePath = cursor.getString(columnIndex); 
     cursor.close(); 

     ImageView imageViewBrw1 = (ImageView) findViewById(R.id.imgViewBrw1); 
     imageViewBrw1.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 

     // -----------------------------------------------------------------------------------// 

     if (requestCode == RESULT_LOAD_IMAGE2 && resultCode == RESULT_OK 
       && null != data) { 
      Uri selectedImage2 = data.getData(); 
      String[] filePathColumn2 = { MediaStore.Images.Media.DATA }; 

      Cursor cursor2 = getContentResolver().query(selectedImage2, 
        filePathColumn2, null, null, null); 
      cursor2.moveToFirst(); 

      int columnIndex2 = cursor2.getColumnIndex(filePathColumn2[0]); 
      String picturePath2 = cursor2.getString(columnIndex2); 
      cursor2.close(); 

      ImageView imageViewBrw2 = (ImageView) findViewById(R.id.imgViewBrw2); 
      imageViewBrw2.setImageBitmap(BitmapFactory 
        .decodeFile(picturePath2)); 
     } 

    } 
} 

답변

0

변화가 내 코드를 확인 같은 코드이

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    if (requestCode == RESULT_LOAD_IMAGE1 && resultCode == RESULT_OK 
      && null != data) { 
     Uri selectedImage = data.getData(); 
     String[] filePathColumn = { MediaStore.Images.Media.DATA }; 

     Cursor cursor = getContentResolver().query(selectedImage, 
       filePathColumn, null, null, null); 
     cursor.moveToFirst(); 

     int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
     String picturePath = cursor.getString(columnIndex); 
     cursor.close(); 

     ImageView imageViewBrw1 = (ImageView) findViewById(R.id.imgViewBrw1); 
     imageViewBrw1.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 

    } 
    // -----------------------------------------------------------------------------------// 

    if (requestCode == RESULT_LOAD_IMAGE2 && resultCode == RESULT_OK 
       && null != data) { 
      Uri selectedImage2 = data.getData(); 
      String[] filePathColumn2 = { MediaStore.Images.Media.DATA }; 

      Cursor cursor2 = getContentResolver().query(selectedImage2, 
        filePathColumn2, null, null, null); 
      cursor2.moveToFirst(); 

      int columnIndex2 = cursor2.getColumnIndex(filePathColumn2[0]); 
      String picturePath2 = cursor2.getString(columnIndex2); 
      cursor2.close(); 

      ImageView imageViewBrw2 = (ImageView) findViewById(R.id.imgViewBrw2); 
      imageViewBrw2.setImageBitmap(BitmapFactory 
        .decodeFile(picturePath2)); 
     } 
} 
+0

mohsin 당신이 답변을 내 질문에 대한 나를 도울 수 이봐 http://stackoverflow.com/questions/17824406/ android-how-to-send-image-to-other-activity-load-image-from-sd-card –

관련 문제