Search code examples
javaandroidif-statementtimedelay

If(statement) delay


This is a curiosity question but is there a way to delay the final line in an if statement.

eg:

if(m_Toolbar.getVisibility() == View.VISBILE) {
               ...........
    m_Toolbar.setVisibility(View.GONE);
}

How would you go about delaying the final line like (ie.GONE)?


Solution

  • Thread.sleep will cause UI to freeze , I suggest to use Handler instead

    if(m_Toolbar.getVisibility() == View.VISBILE) {
        ...........
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                m_Toolbar.setVisibility(View.GONE);
            }
        }, 3000);//3 seconds
    }