I currently have a navigation drawer in which each option does a call to a server to get data. This is done via a class I made that receives the type of call as a string and makes the request in an AsyncTask, returning the data retrieved.
The problem I'm facing is, due to latency the navigation drawer keeps open while it is doing the request and parsing the data, which confuses the user into thinking it crashed.
I wanted it to close and show a ProgressDialog while the operation doesn't finnish. My current code does not work, any idea why? Thanks in advance
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
this.mDrawer.closeDrawer(GravityCompat.START);
this.mDialog.show();
if (id == R.id.nav_data) {
this.dataList = this.myGetterClass.getRequests("some/API/route");
try {
if (this.dataList.size() == 0) {
setTitle("There's no data");
} else {
setTitle("Here's the data");
}
} catch (Exception e) {
setTitle("Without data");
Toast error = Toast.makeText(getApplicationContext(), "Something went wrong", Toast.LENGTH_LONG);
error.show();
}
}
updateScreen(this.dataList);
this.mDialog.dismiss();
return true;
}