使用FirebaseRecyclerAdapter的Firebase搜索实施

时间:2019-03-11 15:28:08

标签: android firebase recycler-adapter

我对FirebaseRecyclerAdapter的想法非常陌生,因此有一个非常基本的问题要问。我正在使用此代码制作一个可让用户输入其专业/服务的应用程序。然后,我希望他们在使用专业名称进行搜索时显示他们的个人资料。这是我正在使用的代码:

private TextInputLayout searchServicees;
private Button searchBtn;
private RecyclerView serviceesList;
private DatabaseReference databaseReference;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);

    searchServicees=findViewById(R.id.searchServicees);
    searchBtn=findViewById(R.id.searchBtn);
    serviceesList=findViewById(R.id.serviceesList);
    serviceesList.setHasFixedSize(true);
    serviceesList.setLayoutManager(new LinearLayoutManager(this));

    databaseReference=FirebaseDatabase.getInstance().getReference("User");

    searchBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String searchTxt=searchServicees.getEditText().getText().toString();
            firebaseSearch(searchTxt);
        }
    });
}

private void firebaseSearch(String search)
{
    Query firebaseQuery=databaseReference.orderByChild("service_Offered").startAt(search).endAt(search+"\uf8ff");
    FirebaseRecyclerAdapter<UserSearch,UsersViewHolder> firebaseRecyclerAdapter=new FirebaseRecyclerAdapter<UserSearch, UsersViewHolder>(
            UserSearch.class,R.layout.list_layout,UsersViewHolder.class,firebaseQuery)
    {
        @Override
        protected void onBindViewHolder(@NonNull UsersViewHolder holder, int position, @NonNull UserSearch model) {
            holder.setDetails(model.getCost_inDollars(),model.getDescription_Of_Service(),model.getName(),model.getService_Offered());
        }

        @NonNull
        @Override
        public UsersViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
            View view= LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_layout,viewGroup,false);
            return new UsersViewHolder(view);
        }
    };
    serviceesList.setAdapter(firebaseRecyclerAdapter);
}

public static class UsersViewHolder extends RecyclerView.ViewHolder
{
    View mView;
    public UsersViewHolder(@NonNull View itemView)
    {
        super(itemView);
        mView=itemView;
    }
    public void setDetails(String userCost,String userDes,String userName,String userService)
    {
        TextView name=mView.findViewById(R.id.searchName);
        TextView service=mView.findViewById(R.id.searchService);
        TextView des=mView.findViewById(R.id.searchDes);
        TextView cost=mView.findViewById(R.id.searchCost);

        name.setText(userName);
        service.setText(userService);
        des.setText(userDes);
        cost.setText(userCost);
    }
}

现在在FirebaseRecyclerAdapter firebaseRecyclerAdapter = new FirebaseRecyclerAdapter(             UserSearch.class,R.layout.list_layout,UsersViewHolder.class,firebaseQuery) 部分显示错误:

FirebaseRecyclerAdapter中的

FirebaseRecyclerAdapter()无法应用于:

预期参数:选项: com ... com.example.servicees.UserSearch>

实际论点:

com ... com.example.servicees.UserSearch> UserSearch.class((java ... com.example.servicees.UserSearch>)

R.layout.list_layout(int)

UsersViewHolder.class(java ... SearchActivity.UsersViewHolder>)

firebaseQuery((com.google.firebase.database.Query)

有人可以告诉我我在哪里做错了吗?

0 个答案:

没有答案