我正在尝试使用以下代码实现搜索功能:
private void firebaseSearch(String searchText) {
Query firebaseSearchQuery = mRef.orderByChild("title").startAt(searchText).endAt(searchText + "\uf8ff");}
但是,Java编译器抛出以下错误:
error: incompatible types: com.google.firebase.database.Query cannot be converted to com.firebase.client.Query
firebaseSearch方法上方的代码:
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import com.firebase.client.Firebase;
import com.firebase.client.Query;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class ArticleScreen extends AppCompatActivity {
RecyclerView mRecyclerView;
FirebaseDatabase mFirebaseDatabase;
DatabaseReference mRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_article_screen);
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager( new LinearLayoutManager(this));
mFirebaseDatabase = FirebaseDatabase.getInstance();
mRef = mFirebaseDatabase.getReference("data");
}
答案 0 :(得分:0)
尝试以下
com.google.firebase.database.Query firebaseSearchQuery = mRef.orderByChild("title").startAt(searchText).endAt(searchText + "\uf8ff");}
查看返回类型orderByChild
答案 1 :(得分:0)
您似乎在应用程序的build.gradle
中包含了两个版本的Firebase SDK,一个是2.x,另一个是最新的。您将需要删除2.x版本,并进行以下更改:
import com.firebase.client.Firebase;
import com.firebase.client.Query;
到
import com.google.firebase.database.Firebase;
import com.google.firebase.database.Query;