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.
Related
I want to add an imageview and texview in each item of navigation drawer (like a cart image(Imageview) and items added in cart(Textview))
This thing known as badge view
Library Link
You can implement it using RecyclerView. Take a look at these series of tutorial:
https://www.youtube.com/watch?v=Wq2o4EbM74k
Lets first define titles and icons of the navigation drawer . So open your projects strings.xml file and add two string arrays .
After that we design xml of item of the navigation drawer. This layout is inflated every time we add a new item in the navigation drawer .
check this link i hope is usefull for you:https://androidbelieve.com/material-navigation-drawer-with-header/
Got the solution, just needed to add app:actionLayout in each of my menuItem and pass the layout in it.
And you can instantiate each of the widgets using
navigationView.getMenu().findItem(menuitemId).getActionView().findViewById(widgetId)
I am working with android fragments.I have a main activity and 3 fragments (tab1,tab2,tab3) in my app.Each fragment contains its own custom listview using base adapter.I want implement action bar search view in each fragment.I can do it using edittext search actions using setting editttext in each layout. But my question is is it possible to do it with actionbar searchview in each tab ?? If yes how can I detect which tab is currently selected or focused ?? and is it possible to do it with custom listview in fragment?? Please help me with some links or answer. Thanks in advance :)
Yes, the answer for all your questions its "yes".
You can use only one search box to filter all the listviews in all tabs / fragments. (I assume this is what you are trying to do)
TabHost has a method getCurrentTab() which returns the index of the tab that's in focus.
The content of the search bar (which is an EditText) you know now to which fragment to send. You can use this to filter the ListView.
I am developing an Android application and I have the standard list and details implemented with fragments. In case that only one pane is shown, I want to dynamically set the action bar title after transition depending on the selected item. Where should I do that?
I have already put the index of the selected item in the intent and forwarded it to the fragment, so both detail activity and detail fragment know about it. Logically, I would set the title in the fragment, otherwise I have to deal with my content in the activity. However, I also have to check whether I am in one or two pane mode which is done in the activity. So, where is the right place for updating the title?
For me, updating the title (and everything related to the content) belongs to the fragment. I was first thinking about using an interface for invoking an updateTitle method of the fragment from the activity. Because of the high complexity for such a simple thing, I rejected the idea. Instead, I check in the fragment whether a detail fragment is displayed, in order to know whether there are one or two panes on the screen. After that, I simply invoke getActivity().setTitle(title) from the fragment with my title as parameter. This seems to be much shorter.
I would still appreciate each answer telling me what is the best practice in respect to this. But for now, my problem is solved.
I need to create an activity with an ActionBar, so that if you press the action bar buttons, the contents of the activity display the same information in different layout (one is a pie chart and the other a listview).
I don't want to use tabs or a viewpager, so what would be the best way to do this?
Build each view in a separate fragment, and use the actionbar buttons to set the current visible fragment.
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.