Je veux utiliser admob avec recyclerview mais il y a un problème. J'ai besoin de cacher certains éléments qui appartiennent au viewholder. Je dois masquer l'image à laquelle appartient l'ImageView. Lorsque je clique sur holder.btnReklamIzle, l'image dans cette position doit être cachée dans la méthode onRewardedVideoAdLoaded. Comment puis-je transmettre la position à la méthode onRewardedVideoAdLoaded?

 public View onCreateView(@NonNull LayoutInflater inflater,
                         ViewGroup container, Bundle savedInstanceState) {

    View root = inflater.inflate(R.layout.fragment_kuponlar, container, false);

    mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(KuponlarFragment.this.getActivity());
    mRewardedVideoAd.setRewardedVideoAdListener(this);

    tahminlerRecyclerView = root.findViewById(R.id.tahminlerRecyclerView);
    linearLayoutManager = new LinearLayoutManager(this.getActivity());
    tahminlerRecyclerView.setLayoutManager(linearLayoutManager);
    tahminlerRecyclerView.setHasFixedSize(true);
    loadRewardedVideoAd();

    fetch();
    return root;
}

private void loadRewardedVideoAd() {
    mRewardedVideoAd.loadAd(getString(R.string.admob_ads_id),
            new AdRequest.Builder().build());
}

private void fetch() {
    Query query = FirebaseDatabase.getInstance()
            .getReference()
            .child("tahminler");

    FirebaseRecyclerOptions<Mac> options =
            new FirebaseRecyclerOptions.Builder<Mac>()
                    .setQuery(query, new SnapshotParser<Mac>() {
                        @NonNull
                        @Override
                        public Mac parseSnapshot(@NonNull DataSnapshot snapshot) {
                            return new Mac((double)snapshot.child("oran").getValue(),
                                    snapshot.child("tahmin").getValue().toString(),                     
                            );
                        }
                    })
                    .build();

    adapter = new FirebaseRecyclerAdapter<Mac, ViewHolder>(options) {
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.tahmin_tasarim_recyclerview, parent, false);



            return new ViewHolder(view);
        }


        @Override
        protected void onBindViewHolder(final ViewHolder holder, final int position, Mac mac) {


            holder.btnReklamIzle.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mRewardedVideoAd.isLoaded()) {
                        mRewardedVideoAd.show();                    
                    }
                }});
        }
    };
    tahminlerRecyclerView.setAdapter(adapter);
}

@Override
public void onRewardedVideoAdLoaded() {

}

public class ViewHolder extends RecyclerView.ViewHolder {

public ImageView image;

    public ViewHolder(View itemView) {
        super(itemView);
        image = itemView.findViewById(R.id.image);
    }
}
0
jonyiash 13 janv. 2020 à 22:58