我想在android中的searchview中提交文本提交的新片段 我试过这个
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
//*** setOnQueryTextFocusChangeListener ***
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
Toast.makeText(MyDrawerActivity.this, "word is:- "+query, Toast.LENGTH_SHORT).show();
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
Bundle bundle=new Bundle();
bundle.putString("word", query);
BlankFragment bm = new BlankFragment();
bm.setArguments(bundle);
ft.replace(R.id.main_container, bm);
ft.addToBackStack(null);
ft.commit();
return true;
}
@Override
public boolean onQueryTextChange(String searchQuery) {
return true;
}
});
我必须将onQueryTextSubmit(String query)“query”传递给该片段页面 感谢