I have made a bottom tab bar in the application.What I want is that when I click on that tab bar. A new Menu Type List should be Opened/PopUp and when i click on any of the list it should pop down Back.
I know how to create seperate activity but dont know how to create the Menu Type Pop-Up list.
You may use OnClickListener on the "Tab bar"; implement the onClick(View) method to pop a new view which has your list.
Do the same on list (may be you have to use performItemClick()) to go back to previous view or whichever view you want.
you can simply create a menu and then open it onClick'ing the tab bar..
use the method openOptionsMenu(); to do this.
Related
I would like to click on an item of a listview to show another listview of other items, what can I do?
in my application I have a main Activity, where I have inserted a bottom view navigation, when you click on an item in the bottom view menu, the corresponding fragment appears in the main activity.
my listview is in the first fragment, and in the same fragment the next screen must appear, after the click in the listview.
do I have to replace the fragment of the listview with another one or can I replace only the listview? how?
Thanks for the attention
Instead of those options (replacing the fragment / list view), you could use the onItemSelected method to repopulate the list view object with the new list. Since you already know how to do this, it would seem the simplest option. A simple switch statement would suffice.
I have 2 fragments between which I can navigate with a bottom navigation bar. I also have an overflow menu with an item which shows an edittext dialog.
I want that when I write and validate text in the dialog, the currently displayed fragment's item on the nav bar changes of title. I don't know how to change text of a specific item.
I hope my question is understandable. I have been searching through SO but I didn't find any corresponding answers.
In Kotlin
bottom_nav_view.menu.findItem(R.id.bottom_nav_item).title = "TITTLE"
in Java
bottom_nav_view.getMenu().findItem(R.id.bottom_nav_item).setTitle( "TITTLE")
If you define an id for the item you want to change in the layouts menu (add the line android:id="#+id/myid"), you can find that item in the code by using findViewById (R.id.myid). Then, just set the new the title depending on what the item is.
Without any code I can only guess that you setup a ViewPager with the TabLayout method yourTabLayout.setupWithViewPager(yourViewPagerAdapter);.
If it is so, you can simply set a title using
yourTabLayout.getTabAt(position).setText(yourTitle); where position is 0 for first tab and 1 for second tab.
If you post some code I can try to specify my answer on your code and the way you are adding the fragments to your activity.
I am trying to make an App on android. I have made the slide in menu bar like the one shown in the the picture below. The blue bar. Now what I want is that my every screen should show the same menu options. Not those with the back button. How do I do that? Should I make one header and call that in every class? Right now I have an Activity and everything else is a fragment.
I can post my code here as well.
make a Parent Activity and make this acion bar in it.inherit your all activities from this parent activity and just remove setContentView(R.layout.layoutname) from your child activity.
this works in your scenario when you are using fragments so you don't need the layout for activity. so your fragment container would be your parent activity..
I have an activity which has 2 fragments.
1 fragment is visible at a time and each fragment has a different option menu.
I can achieve this behavior by 2 different ways.
1 - I can add different menu for each fragment by calling onCreateOptionsMenu in each friengment.
2 - I can have only one menu at activity level and can select to show particular option in onPrepareOptionsMenu
What I want to know is:
Which is the preferable way to implement this functionality?
What is recommended?
Hope this helps
Adding items to the Action Bar
Your fragments can contribute menu items to the activity's Options Menu (and, consequently, the Action Bar) by implementing onCreateOptionsMenu(). In order for this method to receive calls, however, you must call setHasOptionsMenu() during onCreate(), to indicate that the fragment would like to add items to the Options Menu (otherwise, the fragment will not receive a call to onCreateOptionsMenu()).
Any items that you then add to the Options Menu from the fragment are appended to the existing menu items. The fragment also receives callbacks to onOptionsItemSelected() when a menu item is selected.
You can also register a view in your fragment layout to provide a context menu by calling registerForContextMenu(). When the user opens the context menu, the fragment receives a call to onCreateContextMenu(). When the user selects an item, the fragment receives a call to onContextItemSelected().
http://developer.android.com/guide/components/fragments.html
I would follow the first option as having a dedicated resource menu for each fragment seems cleaner and also reduces the code complexity you would have in order to maintain what is visible and what is not (if you would go through onPrepareOptionsMenu and have code to hide & show different menus).
If you have some actions in your fragments, then you could create a base fragment class that each of your fragments would extend from.
In my app, I want to use an ActionBar Spinner for navigation, although I know that this is not really the purpose of the Spinner. My problem is, that the first item in the Menu list is selected automatically when the Activity is started and a click on this first item doesn't trigger the Listener, as long as the first item is "active". What is the best and least hacky way to implement a fully working navigation menu looking exactly the same as the Spinner menu of the Actionbar? (i.e. with this small arrow on the bottom right etc.)