According to the DrawerLayout documentation, "Avoid performing expensive operations such as layout during animation as it can cause stuttering".
Thus, I've tried waiting for the drawer to close before proceeding:
@Override public void onItemClick(AdapterView parent
, View view
, int position
, long id) {
// Close the drawer
mDrawerLayout.closeDrawer(mDrawerList);
ExecutorService es = Executors.newSingleThreadExecutor();
final int mPosition = position;
Thread navThread = new Thread(new Runnable() {
@Override public void run() {
// Wait for the drawer to close
while (mDrawerLayout.isDrawerOpen(mDrawerList));
// Initialize the Fragments.
runOnUiThread(new Runnable() {
@Override public void run() {
selectNavigationItem(mPosition);
}
});
}
});
es.submit(navThread);
es.shutdown();
}
Even though it works, Lint warns me about the empty while loop. How can I achieve this effect without the empty while-loop?
In the ListView.OnItemClickListener
:
@Override public void onItemClick(AdapterView parent
, View view
, int position
, long id) {
mPosition = position;
mNavigationItemClicked = true;
mDrawerLayout.closeDrawer(mDrawerList);
}
In the DrawerLayout
:
public void onDrawerClosed(View view) {
getSupportActionBar().setTitle(mTitle);
if (mNavigationItemClicked)
selectNavigationItem();
mNavigationItemClicked = false;
}
In selectNavigationItem()
:
switch (mPosition) {
...
}
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