search UI

This commit is contained in:
Fuchimoto1234 2024-01-19 12:30:17 +09:00
parent 1e3a3262a4
commit 834bc35318

View File

@ -86,58 +86,52 @@ public class SearchTopFragment extends Fragment {
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
// Menuの設定
// ActionViewの取得
// 虫眼鏡アイコンを最初表示するかの設定
this.searchView.setIconifiedByDefault(true); this.searchView.setIconifiedByDefault(true);
// Submitボタンを表示するかどうか
this.searchView.setSubmitButtonEnabled(false); this.searchView.setSubmitButtonEnabled(false);
if (!this.searchWord.equals("")) { if (!this.searchWord.equals("")) {
// TextView.setTextみたいなもの
this.searchView.setQuery(this.searchWord, false); this.searchView.setQuery(this.searchWord, false);
} else { } else {
String queryHint = self.getResources().getString(R.string.hello_blank_fragment); String queryHint = self.getResources().getString(R.string.hello_blank_fragment);
// placeholderみたいなもの
this.searchView.setQueryHint(queryHint); this.searchView.setQueryHint(queryHint);
} }
this.searchView.setOnQueryTextListener(self.onQueryTextListener); this.searchView.setOnQueryTextListener(self.onQueryTextListener);
} }
private SearchView.OnQueryTextListener onQueryTextListener = new SearchView.OnQueryTextListener() { private final SearchView.OnQueryTextListener onQueryTextListener = new SearchView.OnQueryTextListener() {
@Override @Override
public boolean onQueryTextSubmit(String searchWord) { public boolean onQueryTextSubmit(String query) {
// SubmitボタンorEnterKeyを押されたら呼び出されるメソッド
return self.setSearchWord(searchWord); return self.setSearchWord(searchWord);
} }
@Override @Override
public boolean onQueryTextChange(String newText) { public boolean onQueryTextChange(String query) {
// 入力される度に呼び出される
return false; return false;
} }
}; };
private boolean setSearchWord(String searchWord) { private boolean setSearchWord(String query) {
if (searchWord != null && !searchWord.equals("")) { if (searchWord != null && !searchWord.equals("")) {
// searchWordがあることを確認
this.searchWord = searchWord; this.searchWord = searchWord;
} }
// 虫眼鏡アイコンを隠す
this.searchView.setIconified(false); this.searchView.setIconified(false);
// SearchViewを隠す
this.searchView.onActionViewCollapsed(); this.searchView.onActionViewCollapsed();
// Focusを外す
this.searchView.clearFocus(); this.searchView.clearFocus();
return false; return false;
} }