diff --git a/app/src/main/java/com/example/citrusclient/views/SearchFragment.java b/app/src/main/java/com/example/citrusclient/views/SearchFragment.java index 928bd04..556f4c7 100644 --- a/app/src/main/java/com/example/citrusclient/views/SearchFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/SearchFragment.java @@ -53,7 +53,7 @@ private final SearchFragment self = this; private SearchView searchView; - private String searchWord; + private String searchWord=""; private MyAdapter adapter; private RecyclerView recyclerView; private RecyclerView recyclerView1; // sort_by用のRecyclerView @@ -130,12 +130,14 @@ public void onItemSelected(AdapterView parent, View view, int position, long id) { // positionに基づいてソートの処理を行う sortBy = position; // 例えば、0が"Sort by Title"、1が"Sort by Author"など + System.out.println(position); loadSearchResults(searchWord, sortBy); } @Override public void onNothingSelected(AdapterView parent) { // 何も選択されていない場合の処理(必要に応じて) + loadSearchResults(searchWord, sortBy); } }); @@ -162,7 +164,10 @@ @Override public boolean onQueryTextChange(String newText) { - adapter.filter(newText); // フィルタリングを実行 +// adapter.filter(newText); // フィルタリングを実行 + searchWord = newText; + loadSearchResults(searchWord, sortBy); + Log.d(TAG, "Search query: " + newText); return true; } }); @@ -179,13 +184,13 @@ if(sortBy != null) sortBy = sort;//ソートはまだ Log.d(TAG, "Search query: " + title + accountId); - if(title != "") { - if (accountId != "") { + if(title != ""|| accountId != ""){ + if(sort != null) { publicBooksViewModel.loadSearchBooks(title, accountId, sortBy);//title,accountidでの検索 System.out.println("title: "+title+" accountId: "+accountId+" sortBy: "+sortBy); - }else { - publicBooksViewModel.loadAllBooks(); } + }else { + publicBooksViewModel.loadAllBooks(); // titleとaccountIdを使って検索 } }