2016-09-26 77 views
1

我正在使用Alert對話框獲取Image for User team圖片,然後我想在已打開的對話框中顯示圖像預覽。如何使用選定的圖像更新顯示的對話框圖像?

我傳遞圖像文件,其中顯示我的對話框片段,但我怎麼可以更新ImageView這是在對話框我嘗試更新適配器由我可以通知數據,但還是我在具有通話後收到空適配器該片段

public void passingImage(Image image) { 
    testAdapter.notifyImage(image); 
} 

這是我的警報對話框代碼

public void showDialogForTeam(ChallengeData mData) { 
    this.mData = mData; 
    dialogForTeam = new Dialog(activity); 
    dialogForTeam.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    dialogForTeam.setContentView(R.layout.dialog_team_selection); 
    dialogForTeam.setTitle("Select Team"); 
    spinner = (Spinner) dialogForTeam.findViewById(R.id.spinner); 
    imgClose = (ImageView) dialogForTeam.findViewById(R.id.imageView); 


    RecyclerView.LayoutManager layoutManager5 = new LinearLayoutManager(getActivity()); 
    rvLogo = (RecyclerView) dialogForTeam.findViewById(R.id.rv_logo); 
    rvLogo.setHasFixedSize(true); 
    rvLogo.setLayoutManager(layoutManager5); 

    rvLogo.setAdapter(testAdapter); 
    btnUpload = (TextView) dialogForTeam.findViewById(R.id.btn_upload_icon); 
    tealLogo = (ImageView) dialogForTeam.findViewById(R.id.team_logo); 


    btnUpload.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      int permissionCheck = ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE); 
      if (permissionCheck == PackageManager.PERMISSION_GRANTED) { 
       openGallery(); 

      } else { 
       Nammu.askForPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, new PermissionCallback() { 
        @Override 
        public void permissionGranted() { 
         openGallery(); 

        } 

        @Override 
        public void permissionRefused() { 

        } 
       }); 
      } 

     } 
    }); 
    GridView gridView = (GridView) dialogForTeam.findViewById(R.id.grid_view); 
    // Instance of ImageAdapter Class 
    gridView.setAdapter(new ImageAdapter(activity, this)); 
    Spinner spinner1 = (Spinner) dialogForTeam.findViewById(R.id.spinner1); 
    final LinearLayout llMyteam = (LinearLayout) dialogForTeam.findViewById(R.id.ll_m_team); 
    final RecyclerView recyclerViewTeam = (RecyclerView) dialogForTeam.findViewById(R.id.rv_team); 
    String[] strings = new String[0]; 
    if (mData.getIsTeamcreater().equals("true")) { 
     strings = new String[]{"Join as Team Member", "Create Team"}; 
    } else 
     strings = new String[]{"Join as Team Member"}; 
    spinner.setAdapter(new ArrayAdapter<>(activity, R.layout.row_simple_text, strings)); 
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 
     @Override 
     public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { 
      if (parent.getItemAtPosition(position).toString().equals("Join as Team Member")) { 
       llMyteam.setVisibility(View.GONE); 
       recyclerViewTeam.setVisibility(View.VISIBLE); 
      } else { 
       llMyteam.setVisibility(View.VISIBLE); 
       recyclerViewTeam.setVisibility(View.GONE); 
      } 
     } 

     @Override 
     public void onNothingSelected(AdapterView<?> parent) { 

     } 
    }); 
    spinner1.setAdapter(new ArrayAdapter<>(activity, R.layout.row_simple_text, strings)); 
    if (mData.getTeams() != null && mData.getTeams().size() > 0) { 
     RecyclerView.LayoutManager layoutManager4 = new LinearLayoutManager(activity); 
     recyclerViewTeam.setHasFixedSize(true); 
     recyclerViewTeam.setLayoutManager(layoutManager4); 
     JoinTeamChallengeAdapter allTeamAdapter = new JoinTeamChallengeAdapter(activity, mData.getTeams(), this); 
     recyclerViewTeam.setAdapter(allTeamAdapter); 
    } 

    imgClose.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      dialogForTeam.dismiss(); 
     } 
    }); 
    dialogForTeam.show(); 

} 

public void openGallery() { 
    ImagePicker.create(activity) 
      .folderMode(true) // folder mode (false by default) 
      .folderTitle("Folder") // folder selection title 
      .imageTitle("Tap to select") // image selection title 
      .single() // single mode 
      .limit(1) // max images can be selected (99 by default) 
      .showCamera(true) // show camera or not (true by default) 
      .imageDirectory("Camera") // directory name for captured image ("Camera" folder by default) 
      .start(9686); // start image picker activity with request code 
} 

MianActivity

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    Log.e(TAG, "onActivityResult :" + requestCode); 
    if (requestCode == 9686) { 
     ArrayList<Image> images = data.getParcelableArrayListExtra(ImagePickerActivity.INTENT_EXTRA_SELECTED_IMAGES); 
     if (images.size() > 0 && images.size() == 1){ 
      image = images.get(0); 
      mainHomeFragment.passingImage(image); 
     } 

    } else if (requestCode == 9687) { 
     ArrayList<Image> images = data.getParcelableArrayListExtra(ImagePickerActivity.INTENT_EXTRA_SELECTED_IMAGES); 
     if (images.size() > 0 && images.size() == 1) 
      onPhotoReturned(images.get(0)); 
    } 

    super.onActivityResult(requestCode, resultCode, data); 

} 

回答

0

Android Developer Page下點獲取縮略圖是一個示例,其中顯示瞭如何在用Intent捕獲後在活動的現有ImageView中添加照片。我希望這是你正在尋找的。

編輯:

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { 
     Bundle extras = data.getExtras(); 
     Bitmap imageBitmap = (Bitmap) extras.get("data"); 
     mImageView.setImageBitmap(imageBitmap); 
    } 
} 

正如所看到的,則可以通過其需要一個位圖命令setImageBitmap(image)改變一個圖像圖。如果這對您沒有幫助,請嘗試查看Api ImageView

+0

我想在對話框圖像視圖和對話框上顯示 –

+0

雖然此鏈接可能回答問題,但最好包含答案的基本部分並提供參考鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 - [來自評論](/評論/低質量帖/ 13794831) –

+0

更改並添加頁面中的基本代碼感謝您的建議@ AdityaVyas-Lakhan –