what I want to achieve is Upon click, app shows toasts message "TEXT1", and keeps showing TEXT1 until finish other function call 20 times at a random interval/delay. After calling function,shows toast message "TEXT2". My problem: TEXT1 does not show until app finishes function call. and TEXT1 keeps up for the time it takes to execute 20 times function call,then TEXT2 shows up.My code:
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.example:
                Toast.makeText(getBaseContext(),"Please wait until finish",Toast.LENGTH_SHORT).show();
                int i = 0;
                while (i <= 19 ){
                    int delay = new Random().nextInt(5000);
                    try {
                            Thread.sleep(delay);
                        } catch(InterruptedException ex) {
                            Thread.currentThread().interrupt();
                        }
                    //some function here
                    i++;
                }
                Toast.makeText(getBaseContext(),"Finished",Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
 
     
    