我一直在搜索自动完成textview,但我似乎无法弄清楚如何在firebase回收器适配器中实现它?我看到了这个帖子:How can I load an AutoCompleteTextView from a list of Firebase data?
但我不知道如何在我的程序中实现它。
这是我的代码部分,
private void firebaseUserSearch(String searchText) {
String spinnerSearchs=spinnerSearch.getSelectedItem().toString();
Toast.makeText(getActivity(), "Started Search", Toast.LENGTH_LONG).show();
if(spinnerSearchs.equals("Book Title")){
Query firebaseQuerySearch = mBookDatabase.orderByChild("bookTitle").startAt(searchText).endAt(searchText + "\uf8ff");
FirebaseRecyclerOptions bookOptions= new FirebaseRecyclerOptions.Builder<Book>().setQuery(firebaseQuerySearch,Book.class).build();
mBook = new FirebaseRecyclerAdapter<Book, UsersViewHolder>(bookOptions) {
@Override
protected void onBindViewHolder(final UsersViewHolder holder, final int position,final Book model) {
holder.setDetails(model.getBookId(),model.getBookTitle(),model.getAuthorName());
holder.setItemClickListener(new ItemClickListener() {
@Override
public void OnClick(View view, int position, boolean isLongClick) {
Intent intent = new Intent(getActivity().getBaseContext(),Borrow.class);
intent.putExtra(BOOK_ID,model.getBookId());
getActivity().startActivity(intent);
}
});
holder.setIsRecyclable(false);
}
@Override
public UsersViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.book_layout,parent,false);
return new UsersViewHolder(view,bookList);
}
};
mSearchList.setAdapter(mBook);
} else if(spinnerSearchs.equals("Author")){
Query firebaseQuerySearch = mBookDatabase.orderByChild("authorName").startAt(searchText).endAt(searchText + "\uf8ff");
FirebaseRecyclerOptions bookOptions= new FirebaseRecyclerOptions.Builder<Book>().setQuery(firebaseQuerySearch,Book.class).build();
mBook = new FirebaseRecyclerAdapter<Book, UsersViewHolder>(bookOptions) {
@Override
protected void onBindViewHolder(final UsersViewHolder holder, final int position,final Book model) {
holder.setDetails(model.getBookId(),model.getBookTitle(),model.getAuthorName());
holder.setItemClickListener(new ItemClickListener() {
@Override
public void OnClick(View view, int position, boolean isLongClick) {
Intent intent = new Intent(getActivity().getBaseContext(),Borrow.class);
intent.putExtra(BOOK_ID,model.getBookId());
getActivity().startActivity(intent);
}
});
holder.setIsRecyclable(false);
}
@Override
public UsersViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.book_layout,parent,false);
return new UsersViewHolder(view,bookList);
}
};
mSearchList.setAdapter(mBook);
}
mBook.startListening();
}