简体   繁体   English

单击片段中的按钮,即可更改导航抽屉的内容,而无需关闭活动,只需重新加载活动即可

[英]Changing the content of the Navigation Drawer on click of button from the fragment, without closing the activity, just reloading it

I am developing an application where i specifically need to change the navigation drawer Items on user selection. 我正在开发一个应用程序,在该应用程序中,我特别需要根据用户选择更改导航抽屉项目。

For eg: I have an application which has sports grid view with 6 Different sports to choose from. `1> Cricket 2> Football 3> Baseball 4> Tennis 5> Hockey 6> Basketball.`
When the user selects `Cricket-> i want to change the Navigation items to 
1> Bat 
2>Ball 
3>Pitch info 
4> Rules etc.`

When the user selects `2> Football` the navigation drawer items should change to.

    1> Football info
    2> Rules
    3> Doging tricks etc..
When user selects `3> Baseball` the navigation drawer items should change to 

    1> Baseball info
    2> Baseball bat info
    3> Baseball Player info
    etc

Is it possible to do so in android. 是否有可能在android中这样做。

The Navigation Drawer is a fragment with a listview in it. 导航抽屉是其中包含列表视图的片段。 As described here: http://developer.android.com/training/implementing-navigation/nav-drawer.html 如此处所述: http : //developer.android.com/training/implementing-navigation/nav-drawer.html

So you can just change the array of the list and you are ready to go. 因此,您只需更改列表的数组就可以了。 (code from the link above) (来自上面链接的代码)

mPlanetTitles = getResources().getStringArray(R.array.planets_array);

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout =(DrawerLayout)findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); mDrawerList =(ListView)findViewById(R.id.left_drawer);

// Set the adapter for the list view mDrawerList.setAdapter(new ArrayAdapter(this, R.layout.drawer_list_item, mPlanetTitles)); //为列表视图设置适配器mDrawerList.setAdapter(new ArrayAdapter(this,R.layout.drawer_list_item,mPlanetTitles));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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