Possible duplicate.
Android - Add bottom navigation view dynamically
How can I add a menu dynamically to bottom navigation view?
You can dynamically get the menu from your navigation view, then add a new menu item with you JSON response.
In your OnNavigationItemSelectedListener you can change the URL of your webview.
EDIT 1
Maybe I misunderstood something. Do you want to populate a Navigation Bar with your JSON response ? In that case, my links above can help you.
Do you want to populate a Navigation Drawer with your JSON response ?
In that case you should begin read this : https://developer.android.com/training/implementing-navigation/nav-drawer.html
Edit your activity layout :
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
- content_frame will contain your fragment with a WebView.
- left_drawer will contain your dynamics links.
Get the left_drawer :
mDrawerList = (ListView) findViewById(R.id.left_drawer);
When you get your JSON response just set a adapter to your mDrawerList :
public void onResponse(Call<List<NavBarResult>> call, Response<List<NavBarResult>> response) {
// result is a private List<Result> attribute of the class.
result = response.body();
// Set the adapter for the list view
mDrawerList.setAdapter(new ArrayAdapter<Result>(this,
android.R.layout.simple_list_item_1, result));
// Set the list's click listener
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
}
This way, your Drawer Layout will be populated with your JSON response dynamically.
Then you just have to define your OnItemClickListener to call a new fragment when you click on an item of your list.
private class DrawerItemClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
}
MyFragment is not developp here but it would contain a webView and wait for a ARG_LINK that should be an URL to display in its webView.
private void selectItem(int position) {
// Create a new fragment and specify the link to show based on position
Fragment fragment = new MyFragment();
Bundle args = new Bundle();
args.putString(MyFragment.ARG_LINK, result.get(position).getUrl());
fragment.setArguments(args);
// Insert the fragment by replacing any existing fragment
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment)
.commit();
// Highlight the selected item and close the drawer
mDrawerList.setItemChecked(position, true);
mDrawerLayout.closeDrawer(mDrawerList);
}
Hope it help you this time !