lundi 23 février 2015

Code not working (Randomize Array)

Hey i wanted to ask for help since i dont know why my code is not working. Im new to android programming and wanted to ask for help.



public class MotivationalQuotesMenu extends Activity {

int [] images = {R.drawable.mem1, R.drawable.mem2, R.drawable.mem3};

public static int[] RandomizeArray(int[] images){
Random rgen = new Random(); // Random number generator

for (int i=0; i<images.length; i++) {
int randomPosition = rgen.nextInt(images.length);
int temp = images[i];
images[i] = images[randomPosition];
images[randomPosition] = temp;
}

return images;
}


And then...



class loladapter extends ArrayAdapter<String> {
Context context;
//class that shows a specific row in listview

private loladapter(Context c, String[] titles, int imgs[]) {


super(c, R.layout.singlerow, R.id.textView, titles);
this.context = c;
images = imgs;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.singlerow, parent, false);
ImageView myimageie = (ImageView) row.findViewById(R.id.imageView);

myimageie.setImageResource(images[position]);
return row;

}
}


Random images wont show.. just the same array with the same order





Aucun commentaire:

Enregistrer un commentaire