我使用daimajia imageslider库从数据库中获取我的url图像数据,但它无法正常工作。 imageslider中的图像仅显示一个。任何人都可以帮我解决这个问题吗?
谢谢:)
StringRequest stringRequestSlider = new StringRequest(Request.Method.GET, AppServer.URL_Select_Iklan,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("Iklan", response);
try {
ArrayList<Iklan> iklanList = new JsonConverter<Iklan>().toArrayList(response, Iklan.class);
HashMap<String, String> url_maps = new HashMap<>();
for (Iklan iklan : iklanList) {
url_maps.put(iklan.getJudul_iklan(), AppServer.URL_Select_Poster + iklan.getPoster_iklan());
}
Log.d("HashMap response", String.valueOf(url_maps));
for (String name : url_maps.keySet()) {
sliderView.description(name).image(url_maps.get(name)).setScaleType(BaseSliderView.ScaleType.CenterCrop);
sliderLayout.setCustomAnimation(new DescriptionAnimation());
sliderView.bundle(new Bundle());
sliderView.getBundle().putString("extra", name);
Log.d("Value of HashMap", name);
sliderLayout.addSlider(sliderView);
}
sliderLayout.setCustomIndicator((PagerIndicator) view.findViewById(R.id.custom_indicator));
//sliderLayout.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
sliderLayout.setDuration(3500);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
try {
pDialog.setVisibility(View.GONE);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
);
public class Iklan {
public String judul_iklan, poster_iklan;
public Iklan() {
}
public String getJudul_iklan() {
return judul_iklan;
}
public void setJudul_iklan(String judul_iklan) {
this.judul_iklan = judul_iklan;
}
public String getPoster_iklan() {
return poster_iklan;
}
public void setPoster_iklan(String poster_iklan) {
this.poster_iklan = poster_iklan;
}
}
答案 0 :(得分:0)
我认为您应该在foreach语句中创建新的sliderView
,并使用sliderLayout
方法将其添加到addSlider
。
sliderLayout.setCustomAnimation(new DescriptionAnimation());
for (String name : url_maps.keySet()) {
sliderView = new DefaultSliderView(getApplicationContext()); //create new sliderview
sliderView.description(name).image(url_maps.get(name)).setScaleType(BaseSliderView.ScaleType.CenterCrop);
sliderView.bundle(new Bundle());
sliderView.getBundle().putString("extra", name);
Log.d("Value of HashMap", name);
sliderLayout.addSlider(sliderView);
}
希望得到这个帮助。