Start new activity from SearchView

前端 未结 3 1198
清酒与你
清酒与你 2020-12-13 02:53

I have 2 activities: the first has a action bar with a search view, the second should display the results of the search query.

androidmanifest:

    &         


        
3条回答
  •  忘掉有多难
    2020-12-13 03:30

    I understood the problem i had also faced the same, This is happening because you are passing the current component name by passing the

    getComponentName()

    This will be initialize by the current activity name so you need to initialize it with the searchable activity name in given below format and pass the same Component instance it starts the new activity.

        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        search.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(this, SearchResultsActivity.class)));
        search.setQueryHint(getResources().getString(R.string.search_hint));
    

    Hope it I have answered the Question!

提交回复
热议问题