使用daimajia滑块库的Firebase Image Slider?

时间:2018-11-23 15:50:54

标签: java android json firebase-realtime-database android-viewpager

我在我的项目中使用Firebase实时数据库。我将带有URL的图像存储在Firebase实时数据库的json中。我使用来自Firebase的daimajia.slider:library检索了图像。但我不了解如何使用我存储在Firebase实时数据库的json中的url在thoes滑块图像上设置onClickListner。

到目前为止,我的Java代码是

final DatabaseReference banners = database.getReference("Banner");
        banners.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                for (DataSnapshot postSnapShot : dataSnapshot.getChildren())

                {
                    Banner banner = postSnapShot.getValue(Banner.class);
                    imageList.put(banner.getName() + "_" +banner.getUrl() ,banner.getImage());
                }

                for (String key : imageList.keySet())

                {
                    DefaultSliderView defaultSliderView = new DefaultSliderView(getContext());
                    defaultSliderView
                            .image(imageList.get(key));

                    mSlider.addSlider(defaultSliderView);
                    banners.removeEventListener(this);

                }

                mSlider.setPresetTransformer(SliderLayout.Transformer.Default);
                mSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
                mSlider.setDuration(4000);

            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }

        });

        mSlider.setPresetTransformer(SliderLayout.Transformer.Background2Foreground);

我的模型班级

public class Banner {

    private String Name;
    private String Image;
    private String Url;

    public Banner(){

    }

    public Banner (String name, String image, String url) {

        this.Name = name;
        this.Image = image;
        this.Url = url;

    }

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }

    public String getImage() {
        return Image;
    }

    public void setImage(String image) {
        Image = image; }

    public String getUrl() {
        return Url;
    }

    public void setUrl(String url) {
        Url = url;
    }
}

0 个答案:

没有答案