我打電話針對不同導航項目的相同活動取決於需求。我的問題是如何避免基於id的同一導航項的同時點擊。如果我設置標誌剩餘的物品,這是同一活動的呼叫也無法正常工作,請幫助我。如何避免同時點擊導航項目
代碼
if (id == R.id.nav_Issue_Based) {
try { String fileName = "assessments.pdf";
viewPdfActivity(fileName, "Issue Based");
drawer.closeDrawer(GravityCompat.START);
} catch (Exception e) { e.printStackTrace(); } }
另一
private void viewPdfActivity(String fileName, String title) {
try {
Bundle bundle = new Bundle();
bundle.putSerializable("file_name", fileName);
b undle.putString("title", title);
startActivity(context, bundle, DocumentsLoaderActivity.class);
}
catch (Exception e) {
e.printStackTrace(); }
}
更多的代碼
private void startActivity(Context context, Bundle b, Class<?> cls) {
try {
Intent intent = new Intent(context, cls);
if (b != null) {
intent.putExtras(b);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
}
context.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
請把一些代碼在這裏 –
如果(ID == R.id.nav_Issue_Based){ 嘗試{ String fileName =「assess.pdf」; viewPdfActivity(fileName,「Issue Based」); drawer.closeDrawer(GravityCompat.START); (例外e){ e.printStackTrace(); } } –
private void viewPdfActivity(String fileName,String title){ try {Bundle bundle = new Bundle(); bundle.putSerializable(「file_name」,fileName); bundle.putString(「title」,title); startActivity(context,bundle,DocumentsLoaderActivity.class); (例外e){ e.printStackTrace();} } –