-1

Hello i am new to android. I want the navigation drawer scroll to bottom on an item click. Is it possible?

 if (id == R.id.setting){
     --CODE--
}

Here if setting is selected i want the navigation drawer to scroll down to bottom. How can it do it? please help.

2 Answers 2

0

If I understood it correctly, id.settings is a button, to add the functionality when a user clicks a button you should use this code:

Button settingsBtn = (Button) findViewById(R.id.settings);
            settingsBtn.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    --CODE--
                }
            });
1
  • its not button. Its an item on navigation drawer. When that item is clicked i want the navigation drawer to be scrolled at bottom.
    – Sudeep
    Sep 20, 2018 at 9:42
0

You can use onNavigationItemSelected() to handle NavigationDrawer items.

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

    switch (item.getItemId()) {

       case R.id.setting: {
        // do something when clicked
          break;
        }  
    }
    //close navigation drawer
    mDrawerLayout.closeDrawer(GravityCompat.START);
    return true;
}

And add implements NavigationView.OnNavigationItemSelectedListener to your Activity :

public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener

Remember to initialize and set the listener in onCreate():

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.