gpt4 book ai didi

java - Firebase 搜索无法显示结果

转载 作者:太空宇宙 更新时间:2023-11-04 09:06:08 25 4
gpt4 key购买 nike

我想在我的应用上基于 Firebase 制作搜索数据。我已按照互联网上的说明进行搜索 Firebase。它没有显示错误,但是当我单击搜索按钮时,我的回收 View 是空的,没有显示数据。

Here is my code:

     btnSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String searchText = search_cust.getText().toString();
firebaseCustSearch(searchText);
}
});

This is my firebase search method

private void firebaseCustSearch(String searchText) {

Query firebaseSearchQuery = databaseCustomer.orderByChild("custName").startAt(searchText).endAt(searchText + "\uf8ff");

FirebaseRecyclerOptions customerOptions = new FirebaseRecyclerOptions.Builder<Customer>()
.setQuery(firebaseSearchQuery, Customer.class).build();

adapter = new FirebaseRecyclerAdapter<Customer, CustomerList.ViewHolder>(customerOptions) {
@Override
protected void onBindViewHolder(@NonNull CustomerList.ViewHolder holder, int position, @NonNull Customer model) {
holder.setname(model.getCustName());
holder.setaddress(model.getCustAddress());
Toast.makeText(CRUDCustomer.this, model.custName,Toast.LENGTH_SHORT).show();
}

@NonNull
@Override
public CustomerList.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return null;
}
};

listViewCustomer.setAdapter(adapter);
listViewCustomer.setLayoutManager(new LinearLayoutManager(getApplicationContext()));

}

ViewHolder

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Customer customer = customerList.get(position);

holder.textName.setText(customer.getCustName());
holder.textAddress.setText(customer.getCustAddress());
holder.textPhone.setText(customer.getCustPhone());

}

public class ViewHolder extends RecyclerView.ViewHolder{
public TextView textName ;
public TextView textAddress;
public TextView textPhone ;

public ViewHolder(@NonNull View view){
super(view);
this.textName = (TextView)view.findViewById(R.id.cust_name);
this.textAddress = (TextView)view.findViewById(R.id.cust_address);
this.textPhone = (TextView)view.findViewById(R.id.cust_phone);
}

public void setname(String name){

textName.setText(name);

}
public void setaddress(String address){
textAddress.setText(address);
}
}

最佳答案

private void search(String text) { List filterdNames = new ArrayList<>(); for (Modelclass s : modelclass) {

        if (s.getname.contains(text)) {

search.add(s);
}
}

//calling a method of the adapter class and passing the filtered list
sampleAdapter.filterList(filterdNames);
}

关于java - Firebase 搜索无法显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60200466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com