android - Buttons setText from shuffled list item positions display wrong results -
i have string array numbers "25", "50", "75", "100" , i'm using method below shuffle positions of list' s items.
public list<string> listnums() { list<string> numlist = arrays.aslist(nums); collections.shuffle(numlist); return numlist;
i have method assign list items 4 buttons:
protected void settxtnums(){ numgenerator numgen = new numgenerator(); bnum2.settext(numgen.listnums().get(0).tostring()); bnum3.settext(numgen.listnums().get(1).tostring()); bnum4.settext(numgen.listnums().get(2).tostring()); bnum5.settext(numgen.listnums().get(3).tostring()); }
and i'm trying click on button change text above buttons, doesn't work. onclick code this:
case r.id.bnumgen: settxtnums(); break;
the problem generates dublicate values. want every button have different number, positions change.
if include toast testing this:
toast.maketext(getapplicationcontext(), numgen.listbignums().tostring(), toast.length_long).show();
then on toast correct results, buttons different , same values 2 or 3 of them. mistake?
first of did shuffle on different lists rather required one.and second logic wrong.try this.
list<string> numlist = arrays.aslist(nums); public list<string> listnums() { return numlist; } public void shufflelist() { collections.shuffle(intlist); return numlist; }
now :
protected void settxtnums(){ numgenerator numgen = new numgenerator(); numgen.shufflelist(); bnum2.settext(numgen.listnums().get(0).tostring()); bnum3.settext(numgen.listnums().get(1).tostring()); bnum4.settext(numgen.listnums().get(2).tostring()); bnum5.settext(numgen.listnums().get(3).tostring()); }
Comments
Post a Comment