Does somebody know of a tutorial or an example of how to implement the standard Android search interface with Fragment
s? In other words, is it possible to put a standard search with a SearchManager
in a Fragment?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
Here is the example to search something using fragments. Hope it helps and this is what you are looking for:
Using AppCompat support classes v7. Just adding something to @David 's solution from @Rookie solution to get it work properly in a simple manner, here is my fragment code:
MyFragment:
I added the
onActivityCreated
, cuz without callingsetHasOptionsMenu(true);
the system will not know that this fragment needs to interact with the menu.then I removed the line
inflater.inflate(R.menu.main, menu);
because it doubled the menu items since Activity inflated a menu, then Fragment inflated another menuThanks to @David and @Rookie
Use the
ActionBar
andSearchView
. You will be able to handle searches without any connection to Activity. Just set anOnQueryTextListener
to the SearchView.See this post for more details on custom search.
It is quite possible to search in a fragment using the standard ActionBar SearchView ActionView API. This will work back to Android 2.1 (API level 7) too using AppCompat support classes v7.
In your fragment:
In your menu XML
yes its possible,
please implements Search view on your Activity ,'onQueryTextChange' in Activity will also listen the search in fragment, you can check the fragment visibility in 'onQueryTextChange' , if it visible you can call your search method for fragment, its working perfect in my code
i found a work around :) you can override this method (startActivity(Intent) ) in your BaseActivity and then check if the action is ACTION_SEARCH then do your special job :D