2017-10-21 101 views
-1

基本上我使用github中的圖像選擇器庫從gallery中選擇多個圖像。在選擇圖像時沒有問題,即使在獲取uri時也沒有問題,但uris未加載到回收站視圖。它沒有顯示任何錯誤或任何其他消息。圖像沒有加載到recyclerView從圖庫中選擇

我烏里獲取代碼:

public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if (requestCode == Constants.REQUEST_CODE && resultCode == RESULT_OK && data != null) { 
     //The array list has the image paths of the selected images 
     ArrayList<Image> images = data.getParcelableArrayListExtra(Constants.INTENT_EXTRA_IMAGES); 
     ArrayList<Uri> selected=new ArrayList<>(); 
     for (int i = 0, l = images.size(); i < l; i++) { 
      selected.add(Uri.parse(images.get(i).path)); 
     } 
        Toast.makeText(getActivity().getApplicationContext(),selected.toString(),Toast.LENGTH_SHORT).show(); 
        adapter = new CustomRecyclerViewAdapter(getActivity().getApplicationContext(),selected); 
     recyclerView.setAdapter(adapter); 

}} 

適配器類代碼: 「http://www

public void onBindViewHolder(final RecyclerViewHolder holder, final int position) { 
    //ivbackground is imageView 

      Glide.with(holder.ivBackground.getContext()) 
       .load(image.get(position)).into(holder.ivBackground);} 
+0

首先,你應該從活動通過上下文來回收適配器,然後可以使用這樣'Glide.with(上下文).load(image.get(位置))到(holder.ivBackground);' – emrekose26

+0

我不認爲這是問題,因爲可繪製的圖像正在加載沒有任何問題 –

回答

0

類同從URL加載怎麼有架構,Uri還應提供適當的架構「file://」。也許你沒有。 嘗試將它作爲文件傳遞。 Glide.with(holder.ivBackground.getContext()) .load(new File(image.get(position))).into(holder.ivBackground);