无法在recyclerview中显示图像

llycmphe  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(256)

在将图像的lsit传递给arraylist中的recyclerview后,尝试将其显示给recyclerview,但无法显示它。
我正在将图像uri传递给dataadapter并成功接收,但仍然无法在回收器视图中显示图像请指出错误。
图像不显示在recyclerview布局中。
主要活动。

  1. public class SelectedImagePreview extends AppCompatActivity {
  2. private BitmapFactory.Options options;
  3. private RecyclerView viewPager;
  4. private View btnNext, btnPrev;
  5. private DataAdapter adapter;
  6. private LinearLayout thumbnailsContainer;
  7. ArrayList<File> mainfile = new ArrayList<>();
  8. File allfile;
  9. ArrayList<String> filename = new ArrayList<String>();
  10. ArrayList<Uri> images_uri = new ArrayList<Uri>();
  11. //the images to display
  12. String[] imageIDs;
  13. @Override
  14. protected void onCreate(Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.preview_activity);
  17. Bundle extras = getIntent().getExtras();
  18. viewPager = (RecyclerView) findViewById(R.id.view_pager);
  19. if (extras != null) {
  20. //filename.add(extras.getString("filename"));
  21. filename = (ArrayList<String>) getIntent().getSerializableExtra("filename");
  22. Log.e("filename1111", String.valueOf(filename));
  23. Uri imageUri = getIntent().getData();
  24. Log.e("uri", String.valueOf(imageUri), null);
  25. allfile = new File(String.valueOf(imageUri));
  26. mainfile.add(allfile);
  27. images_uri.add(imageUri);
  28. Log.e("name", allfile.getName());
  29. Log.e("name33333333333333", mainfile.toString());
  30. }
  31. adapter = new DataAdapter(this, images_uri);
  32. viewPager.setAdapter(adapter);
  33. }
  34. }

数据适配器.java

  1. package www.welkinfort.com.whatsappgallery;
  2. import android.content.Context;
  3. import android.net.Uri;
  4. import android.support.v7.widget.RecyclerView;
  5. import android.util.Log;
  6. import android.view.LayoutInflater;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.widget.ImageView;
  10. import java.util.ArrayList;
  11. /**
  12. * Created by Admin on 04-Sep-17.
  13. */
  14. public class DataAdapter extends RecyclerView.Adapter<DataAdapter.ViewHolder> {
  15. private ArrayList<Uri> file_url;
  16. private Context context;
  17. public DataAdapter(Context context,ArrayList<Uri> file_url) {
  18. this.context = context;
  19. this.file_url = file_url;
  20. Log.e("filefggdgdgdgd",file_url.toString());
  21. }
  22. @Override
  23. public DataAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) {
  24. View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.row_layout, viewGroup, false);
  25. return new ViewHolder(view);
  26. }
  27. @Override
  28. public void onBindViewHolder(ViewHolder viewHolder, int position) {
  29. viewHolder.img_android.setImageURI(file_url.get(position));
  30. //Picasso.with(context).load(file_url.get(i)).resize(120, 60).into(viewHolder.img_android);
  31. }
  32. @Override
  33. public int getItemCount() {
  34. return file_url.size();
  35. }
  36. public class ViewHolder extends RecyclerView.ViewHolder{
  37. ImageView img_android;
  38. public ViewHolder(View view) {
  39. super(view);
  40. img_android = (ImageView)view.findViewById(R.id.img_android);
  41. }
  42. }
  43. }

活动\u main.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:orientation="vertical"
  7. >
  8. <LinearLayout
  9. android:layout_margin="10dp"
  10. android:layout_width="match_parent"
  11. android:layout_height="match_parent"
  12. android:orientation="vertical">
  13. <android.support.v7.widget.RecyclerView
  14. android:id="@+id/view_pager"
  15. android:layout_width="match_parent"
  16. android:layout_height="match_parent">
  17. </android.support.v7.widget.RecyclerView>
  18. </LinearLayout>
  19. </LinearLayout>

adpter布局.java

  1. <LinearLayout xmlns:card_view="http://schemas.android.com/apk/res-auto"
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent">
  5. <ImageView
  6. android:layout_width="match_parent"
  7. android:layout_height="match_parent"
  8. android:id="@+id/img_android" />
  9. </LinearLayout>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题