Reputation: 57
HashMap<String,Integer> file_maps = new HashMap<String, Integer>();
file_maps.put("M/S 1",R.drawable.rs1);
file_maps.put("M/S 2",R.drawable.rs2);
file_maps.put("M/S 3",R.drawable.rs3);
file_maps.put("M/S 4",R.drawable.rs4);
for(String name : file_maps.keySet()){
TextSliderView textSliderView = new TextSliderView(this);
// initialize a SliderLayout
textSliderView
.description(name)
.image(file_maps.get(name))
.setScaleType(BaseSliderView.ScaleType.Fit)
.setOnSliderClickListener(this);
mDemoSlider.addSlider(textSliderView);
i use this code , suppose to be the first image appear is rs1 , second rs2 , third rs3 and last rs4 ..
But the problem is image rs3 will first display , second rs4 , third rs1 and last rs2 ..
So how i can solve this problem ? or have any idea why this problem happen ..?
Upvotes: 0
Views: 76
Reputation: 10299
Instead of
HashMap file_maps = new HashMap();
Use
HashMap file_maps = new LinkedHashMap();
HashMap makes absolutely no guarantees about the iteration order. It can (and will) even change completely when new elements are added.
LinkedHashMap will iterate in the order in which the entries were put into the map
Upvotes: 1