Im trying to perform the method below however I keep getting the error "Skipped n frames! The application may be doing too much work on its main thread." Ive tried breaking the for and while loops into threads like this
Thread thread = new Thread() {
@Override
public void run() {
try {
// for or while loop here
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
thread.start();
However that didnt work at all either. Any possible fixes for this?
public void newSim(int x) {
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
int buttonWidth = (int) (width * 0.15);
int buttonWidth1 = (int) (width * 0.20);
int buttonHeight1 = (int) (height * 0.20);
ArrayList<Point> intersection = new ArrayList<Point>();
final ArrayList<Point> location = new ArrayList<Point>();
int constraint = 0;
int xC = width - buttonWidth1;
int yC = height - buttonWidth1;
for (int i = 0; i < x; i++) {
for (int j = 0; j < x; i++) {
location.add(new Point(i, j));
constraint++;
}
}
for (int i = 0; i < x; i++) {
Random random = new Random();
Point point = new Point();
point = location.remove(random.nextInt(constraint));
while (intersection.contains(point)) {
intersection.add(point);
point = location.remove(random.nextInt(constraint));
}
Button but1 = new Button(this);
but1.setText(String.valueOf(i));
RelativeLayout r = (RelativeLayout) findViewById(R.id.playLayout);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(buttonWidth, buttonWidth);
layoutParams.setMargins(0, 0, buttonWidth, buttonWidth);
but1.setLayoutParams(layoutParams);
r.addView(but1);
constraint--;
}
}