如何显示使用RecyclerView适配器从火力地堡存储的图片?

问题描述 投票:0回答:1

我想显示使用滑翔(毕加索)在我RecyclerView从火力地堡存储照片。我的问题是:当我尝试与当前上下文填充with参数,我有以下错误:

Cannot resolve method with "this" 

这里是我的适配器的代码。

public class MedAdapterMatin extends RecyclerView.Adapter<MedAdapterMatin.MyViewHolder> {

ArrayList<Medicament> malist;

public MedAdapterMatin(ArrayList<Medicament> malist) {
    this.malist = malist;

}

public static class MyViewHolder extends RecyclerView.ViewHolder {

    ImageView boiteView, pilsView;
    TextView momentPrise, nomMed, nbPrise;
    Context context;
    //Firebase Database
    FirebaseDatabase database;
    DatabaseReference myRef;


    public MyViewHolder(View medView) {
        super(medView);

        boiteView = medView.findViewById(R.id.boite);
        pilsView = medView.findViewById(R.id.cachet);
        momentPrise = medView.findViewById(R.id.moment);
        nomMed = medView.findViewById(R.id.medi);
        nbPrise = medView.findViewById(R.id.nbPrise);
    }

    public void display(Medicament m) {

        //Firebase database
        database = FirebaseDatabase.getInstance();
        myRef = database.getReference().child("PIC_Firebase");
        momentPrise.setText(m.getMomentPrise());
        nomMed.setText(m.getNom());
        //boiteView.setImageURI(Uri.parse(m.getImageAdress()));
      StorageReference profileImageRef = FirebaseStorage.getInstance().getReference("Medicament/" + m.getNom() + ".jpg");
        profileImageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
            @Override
            public void onSuccess(Uri uri) {
               // Picasso.get().load(uri).into(boiteView);
                Glide.with(MedAdapterMatin.getContext()).load(uri).into(boiteView);
            }

        });
        String form = m.getFormePharma();
        /*int resID = context.getResources().getIdentifier(form, "drawable", context.getPackageName());*/
        pilsView.setImageResource(R.drawable.goutte);
        nbPrise.setText("X" + m.getCompriméMatin());


    }

}


@NonNull
@Override
public MedAdapterMatin.MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

    LayoutInflater layoutInflater = LayoutInflater.from(viewGroup.getContext());
    View view = layoutInflater.inflate(R.layout.affichage_medicament, viewGroup, false);
    return new MyViewHolder(view);
}

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    holder.display(malist.get(position));

}


public int getItemCount() {
    return malist.size();
}

}

这是我的MainActivity:

//RecyclerView Matin
private RecyclerView rvMatin;
private MedAdapterMatin medAdapterMatin;
private ArrayList<Medicament> medListMatin;
//RecyclerView Midi
private RecyclerView rvMidi;
private MedAdapterMidi medAdapterMidi;
private ArrayList<Medicament> medListMidi;
//RecyclerView Soir
private RecyclerView rvSoir;
private MedAdapterSoir medAdapterSoir;
private ArrayList<Medicament> medListSoir;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_accueil_p);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    //Firebase database
    database = FirebaseDatabase.getInstance();
    myRef = database.getReference("PIC_Firebase");

    Globals g = (Globals) getApplicationContext();

    //Call ordonnance bdd
    myRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            Ordonnance ord = new Ordonnance();
            Globals g = (Globals) getApplicationContext();

            String ordo = g.getRef_database() + "Ordonnance";
            DataSnapshot dt_ord = (DataSnapshot) dataSnapshot.child(ordo);
            ord = dt_ord.getValue(Ordonnance.class);
            //String date_ord = ord.getDateOrdonnace();
            //ArrayList<Medicament> listmed = ord.getListMed();
            medList = new ArrayList<>();
            medListMatin = new ArrayList<>();
            medListMidi = new ArrayList<>();
            medListSoir = new ArrayList<>();

            medList = ord.getListMed();

            if (medList != null) {
                //Affectation dans les listes de medicaments Matin/Midi/Soir
                for (Medicament ls : medList) {
                    if (!ls.getCompriméMatin().equals(""))
                        medListMatin.add(ls);
                    if (!ls.getCompriméMidi().equals(""))
                        medListMidi.add(ls);
                    if (!ls.getCompriméSoir().equals(""))
                        medListSoir.add(ls);
                }
            }
            //RECYCLER VIEW MATIN
            rvMatin = findViewById(R.id.list_matin);
            medAdapterMatin = new MedAdapterMatin(medListMatin);
            rvMatin.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false));

            //RECYCLER VIEW Midi
            rvMidi = findViewById(R.id.list_midi);
            medAdapterMidi = new MedAdapterMidi(medListMidi);
            rvMidi.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false));

            //RECYCLER VIEW Soir
            rvSoir = findViewById(R.id.list_soir);
            medAdapterSoir = new MedAdapterSoir(medListSoir);
            rvSoir.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false));
            //Set adapters
            rvMatin.setAdapter(medAdapterMatin);
            rvMidi.setAdapter(medAdapterMidi);
            rvSoir.setAdapter(medAdapterSoir);
        }
android firebase-storage android-adapter android-glide
1个回答
0
投票

因为“这种”不给上下文那里。如果你想在活动类的代码,然后通过“ActivityName.this”,或者如果您使用的片段,然后写上“的getContext”,而不是这个。”

Glide.with(ActivityName.this).load(url)."tinto(boiteView); //if you're trying code in Activity class

Glide.with(getContext ()).load(url)."tinto(boiteView); //if you're trying code in Fragment class

© www.soinside.com 2019 - 2024. All rights reserved.