可能な重複
Android - Add bottom navigation view dynamically
How can I add a menu dynamically to bottom navigation view?
あなたは、動的に、あなたJSON応答で新しいメニュー項目を追加し、あなたのナビゲーションビューからメニューを得ることができます。
OnNavigationItemSelectedListenerでは、WebビューのURLを変更できます。
EDIT 1
は、たぶん私は何かを誤解。ナビゲーションバーにJSONレスポンスを入力しますか?その場合、上記の私のリンクがあなたを助けることができます。
ナビゲーション・ドロワーにJSON応答を入力しますか? https://developer.android.com/training/implementing-navigation/nav-drawer.html
編集アクティビティのレイアウト:あなたがこれを読んで開始する必要があり、その場合には
<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は、WebViewのとあなたのフラグメントが含まれています。
- left_drawerにダイナミクスリンクが含まれます。
left_drawerをゲット:あなたはJSONレスポンスは自分mDrawerListにアダプタ設定を取得すると
mDrawerList = (ListView) findViewById(R.id.left_drawer);
:
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());
}
をこのように、自分の引き出しのレイアウトがあなたのJSONが取り込まれます動的に応答する。
次に、リストの項目をクリックしたときに新しいフラグメントを呼び出すためにOnItemClickListenerを定義するだけです。
private class DrawerItemClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
}
MyFragmentはここdeveloppされていないが、それはWebViewのを含めるとそのWebViewの中で表示するためのURLである必要がありARG_LINKを待つでしょう。
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);
}
今回はお手伝い願います!