Answer the question
In order to leave comments, you need to log in
How to make clickable menus in Navigation Drawer?
All health! I am a complete noob in android programming and it just so happened that I was lucky enough to create a Webview application for a website. Of course, due to the latest technologies, without creating a wheel, I began to finish the finished one, which I found on the Internet. And it seems to be nothing, BUT, the ready-made solution turned out to be very informative in terms of documentation and it all came down to paying the authors of this creation in order to understand what they had done here. Let's get to the point:
The project has a file activity_main_drawer.xml consisting of such a tag as < group > inside which is a comment that the block is added programmatically. After 2-3 vidos from hearing Indians on the topic of creating a Navigation Drawer, I tried to add a few menu lines to this file. The menu is displayed, the lines are as expected, but here's the problem! How to make them clickable? So that when the user clicks, it throws at a specific URL.
One of the menu lines looks like this:
< item
android:title="@string/catalogue"
android:id="@+id/catalog_id" />
By the way, in the MainActivity.java file under the
public boolean onOptionsItemSelected(MenuItem item) function,
I tried to add content like this:
else if(item.getItemId() == R.id.catalog_id {
browser.loadUrl(" https://www.mysite.com/catalog ");
return true; }
The result didn't live up to expectations. But as they say, hope dies last, and I have patience over dofiga. Therefore, I ask those who know to help where to look? What tutorial to peep where the task I want is clearly implemented, or share the link. Thanks in advance to everyone who posts!
PS If the source of the project is needed, I also ask you to advise where and how to put it in order to share the link for study correctly
Answer the question
In order to leave comments, you need to log in
The android studio has standard activities, incl. Navigation Drawer Activity, you can see the code there. Click handling is something like this
MainActivity extends ... implements NavigationView.OnNavigationItemSelectedListener
onCreate {
...
nav_view.setNavigationItemSelectedListener(this) // nav_view соответственно элемент дравера
}
// в активности
@Override
public boolean onNavigationItemSelected(MenuItem item) {
if(item.getItemId() == R.id.catalog_id ...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question