You don't need to wait for the fragment transaction to complete, You can call
getSupportFragmentManager().executePendingTransactions();
after your commit() function call.
This will ensure that the transaction is complete.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…