简体   繁体   中英

Open alert dialog in Bottom Navigation View while navigation to next fragment

I am having an BottomNavigationView in my activity and i have five fragments and i have used Navigation Jetpack component.

Each and every time i move to next fragment by clicking the BottomNavigationView item, i have to ask for a confirmation dialog (If i have to navigate from this screen Yes/No). If Yes i can move to next screen else for No i have to dismiss the dialog and proceed.

I there any better in Navigation Jetpack component itself to handle this situation.

I not getting any clear picture for this

When you select BottomNavigationView item, you can should use this code; First step, define BottomNavigationView in onCreate.

    mBtmView = (BottomNavigationView) findViewById(R.id.bottomView);
    mBtmView.setOnNavigationItemSelectedListener(this);

Second step;

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {

    mMenuId = item.getItemId();

    switch (item.getItemId()) {
        case R.id.action_food: {
//Show dialog to there. if reject swipe from your dialog, use setCurrentItem. 
        }
        break;
        case R.id.action_medical: {
//Show dialog to there. if reject swipe from your dialog, use setCurrentItem. 

        }
        break;
        case R.id.action_yoga: {
//Show dialog to there. if reject swipe from your dialog, use setCurrentItem. 

        }
        break;
        case R.id.action_postures: {
//Show dialog to there. if reject swipe from your dialog, use setCurrentItem. 

        }
        break;
    }
    return true;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM