public class MainActivity extends AppCompatActivity { int y; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new MyView(this)); } class MyView extends View { public MyView(Context context) { super(context); } public void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(Color.WHITE); paint.setTextSize(20); canvas.drawColor(Color.BLACK); new CyclerThread().startCycle((i) -> y=i); canvas.drawText(""+ y,100,100, paint); } } } .................................................. .................
public class CyclerThread { public interface Callback { void onValueChanged(int i); } public void startCycle(Callback callback) { Random random = null; for (int op = 0; op>0; op++) { boolean bo = random.nextBoolean(); if (bo == true) { for (int i = 0; i < 5; i++) { try { Thread.sleep(2000); // any action } catch (InterruptedException e) { e.printStackTrace(); } callback.onValueChanged(i); // System.out.println(i); } } else { try { Thread.sleep(5000); // any action } catch (InterruptedException e) { e.printStackTrace(); } } } } }
истинна, then the cycle goes from one to five (i) in two-second increments, and if it lies then the whole cycle stops for five seconds, I need to output many such values, but of course I I will not write dozens of such cycles as the number of cycles will definitely be later and it will always be different - Jonathan