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.
Related
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.
In my app, I need an ActionBar with a dropdown on it (a spinner / setNavigationMode NAVIGATION_MODE_LIST). The ActionBar needs to be visible in all the views/screens of the app, but the content underneath it changes - it's a list of items that when clicked, a detailed view of the item is seen.
The ActionBar state should be persistent throught the different views (e.g. the selected item in the drop down).
What would be the correct way to do it? I can think of:
A base activity that initializes the ActionBar by calling actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST), attaching an adapter if needed etc. (How to persist the dropdown state?)
Using fragments
Another way?
Which of these ways is preferred?
Thanks
I am trying to make an application that has the following design.
Login->Dashboard
Dashboard has a #navigationdrawer having a listview ,of which every item opens a fragment.
Dashboard has a view pager of two pages.
Page 1 : listview
Page2: search bar.
Till now this is in place.
Problem statement :
The #page2 is constant it has to appear on every fragment ,but #page1 changes for every fragment . Can someone help me achieve this.
I am not getting how to do it.
I think you should use search menu item in Dashboard's ActionBar instead of fragment and display it using viewpager. Check following link to make search interface.
http://developer.android.com/guide/topics/search/search-dialog.html
I'm currently designing the following 2 pane layout and I'm wondering on how to implement it.
Link to Wireframe
So far, I made a two pane activity. On the left is a custom ListView fragment. On the right is a detailpane. The detail pane is what I'm having trouble implementing. I don't know how to create a tab view that doesn't use the actionbar and I'm curious if the best way is to use a ton of fragments for the detailpane or just add change the data dynaically.
[The reason I don't want to use the action bar is that I'm using it for my Help/Refill buttons]
So what tools/tutorials/advice can anyone recommend in implementing this?
Additional information:
Categories or the Tabs will be based on a JSON array.
The listview inside the tabs will be filled with items from a JSON array.
Let me know if you need any more information.
I am currently using a FragmentTabHost and it's just perfect!
You can have your ListFragment and a simple Fragment with your details.
And use your FragmentActivity to communicate with them.
You just need to override the onAttach method of your activity which is called when a Fragment is displayed.
I have an Activity with a ViewPager inside.
The ViewPager has 3 pages.
I want to show my dropdown list only in 1 of the 3 pages.
Is there a correct way to do that? Maybe a Show/Hide property or must I change the setNavigationMode of the sherlockActionBar?
Thanks and sorry for my poor English
You can easily hide the DropDown list by using this line of code :
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
Then you can implement an OnPageChangeListener to be notify when the user scrolls.