Hi I have a question on AlertDialog / Toast . When a user clicks on a button , just a message showing "You are right " should be displayed for 1 seconds. When I implement this using toast/alertdialog it executes this but starts the next instruction in the onclick method before the dailog is turned off. How do I fix this?
public class ToastActivity extends Activity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Handler mHandler = new Handler();
for(int i=10;i>=1;i--)
{
Toast.makeText(this, ""+i, Toast.LENGTH_SHORT).show();
}
mHandler.postDelayed(new Runnable(){public void run(){
LinearLayout t=(LinearLayout)findViewById(R.id.l); //This task is delayed by 21 sec.
t.setBackgroundColor(Color.CYAN);
}
}, 21000);
}
}
Statements after toast are executed after toast has disappeared.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With