为什么png文件没有加载到recyclerview中

时间:2019-04-19 07:41:20

标签: android firebase android-recyclerview png picasso

我目前在一个Android项目中工作,我必须在其中将png文件上传到Firebase Realtime数据库中。我的应用程序正在检索图像,但是当我使用png文件时,它仅加载五个png文件,我不知道其他png文件怎么了。 当我使用图片网址进行编辑时,另一张图片却无法正常工作,而我编辑的那张图片开始起作用。 我正在使用Picasso库查看图像... 是否有人遇到相同的错误... 我应该尽快完成项目 如果我使用滑行代替毕加索,这个问题应该解决吗??? myadapter.java


public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
    private DatabaseReference reference;

    static Context context;
    static ArrayList<Profile> profiles;

    public MyAdapter(Context c, ArrayList<Profile> p) {
        context = c;
        profiles = p;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.recyclerview_item, parent, false));
    }


    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.title.setText(profiles.get(position).getTitle());
        holder.desc.setText(profiles.get(position).getDesc());
        Picasso.get().load(profiles.get(position).getImage()).into(holder.image);
    }

    @Override
    public int getItemCount() {
        return profiles.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        TextView title, desc;
        ImageView image;
        Button btn;

        public MyViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.title);
            desc = (TextView) itemView.findViewById(R.id.desc);
            image = (ImageView) itemView.findViewById(R.id.image);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View view) {

            Intent intent = new Intent(context, Main2Activity.class);
            intent.putExtra("URL", profiles.get(getAdapterPosition()).getImage());
            context.startActivity(intent);
        }


    }
}

mainactivity.java


public class helmet extends AppCompatActivity {
    DatabaseReference reference;
    RecyclerView recyclerView;
    ArrayList<Profile> list;
    public MyAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_helmet);
        recyclerView = (RecyclerView) findViewById(R.id.recyclle);
        int numberOfColumns = 3;
        recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.HORIZONTAL));

        recyclerView.setLayoutManager(new GridLayoutManager(this, numberOfColumns));
        reference = FirebaseDatabase.getInstance().getReference().child("helmet");
        reference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                list = new ArrayList<Profile>();
                for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
                    Profile p = dataSnapshot1.getValue(Profile.class);
                    list.add(p);
                }
                adapter = new MyAdapter(helmet.this, list);
                recyclerView.setAdapter(adapter);
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {
                Toast.makeText(helmet.this, "Opsss.... Something is wrong", Toast.LENGTH_SHORT).show();
            }

        });
    }

....

0 个答案:

没有答案