我正在开发一个大学搜索应用程序,但是我无法解决这个错误。
代码如下:
public class searchEngineActivity extends AppCompatActivity {
public String stateSelected;
public String courseSelected;
public RecyclerView searchRecyclerView;
public WebView webView;
public FirebaseRecyclerOptions adapter;
public DatabaseReference databaseReference;
String queryState, queryCourse;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_engine);
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
Bundle bundle = getIntent().getExtras();
stateSelected = bundle.getString("stateSelected");
courseSelected = bundle.getString("courseSelected");
Log.e("arguments",stateSelected+courseSelected );
makeQuery(stateSelected, courseSelected);
searchRecyclerView = (RecyclerView) findViewById(R.id.searchRecyclerView);
webView = (WebView) findViewById(R.id.webView);
searchRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
setAdapter();
searchRecyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.HORIZONTAL));
}
public void makeQuery(String q, String c) {
queryState = q.replaceAll(" ", "-");
queryState = queryState.toLowerCase();
queryCourse = c.toLowerCase();
}
public void setAdapter() {
Query query = FirebaseDatabase.getInstance().getReference().child("searchengines");
FirebaseRecyclerOptions<searchModelClass> options = new FirebaseRecyclerOptions.Builder<searchModelClass>().setQuery(query, searchModelClass.class).build();
adapter = new FirebaseRecyclerPagingAdapter<searchModelClass, androidx.recyclerview.widget.RecyclerView.ViewHolder>(options) {
//@Override
protected void onBindViewHolder(@NonNull searchRecyclerViewHolder holder, final int position, @NonNull searchModelClass model) {
holder.setSiteImage(model.getImage());
holder.setSiteName(model.getName());
holder.setSiteURL(model.getUrl());
}
@Override
protected void onBindViewHolder(@androidx.annotation.NonNull @NonNull RecyclerView.ViewHolder viewHolder, int position, @androidx.annotation.NonNull @NonNull searchModelClass model) {
}
@Override
protected void onLoadingStateChanged(@androidx.annotation.NonNull @NonNull LoadingState state) {
}
@NonNull
//@Override
public searchRecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.search_recycler_view, parent, false);
final searchRecyclerViewHolder viewHolder = new searchRecyclerViewHolder(view);
viewHolder.setOnClickListener(new searchRecyclerViewHolder.ClickListener() {
@Override
public void onClick(View view, int position) {
**databaseReference = adapter.getCurrentList(position);**
databaseReference = databaseReference.child(queryCourse);
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String queryURL = dataSnapshot.getValue(String.class);
queryURL = queryURL.replaceAll("state", queryState);
webView.loadUrl(queryURL);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
return viewHolder;
}
};
searchRecyclerView.setAdapter(adapter);
}
@Override
public void onStart() {
super.onStart();
FirebaseRecyclerPagingAdapter<Object, RecyclerView.ViewHolder> firebaseRecyclerAdapter = null;
firebaseRecyclerAdapter.startListening();
} //UPDATING RECYCLER VIEW REGULARLY FROM THE START OF FRAGMENT
}
错误是:
无法解析'FirebaseRecyclerOptions'中的'getCurrentList'方法:101
我尝试使用其他库来代替firebase ui库,但后来我不得不改变我的整个代码。我还能做什么?
您的adapter
对象是FirebaseRecyclerPagingAdapter
类型的对象。当你尝试在这样一个对象上调用getCurrentList(position)
时,预期的行为是得到以下错误:
Cannot resolve method 'getCurrentList' in 'FirebaseRecyclerOptions':101
因为适配器类中没有getCurrentList()
方法。此外,如果存在这样的方法,正如其名称所示,它将返回一个列表,而不是一个DatabaseReference
对象。所以看看你的代码,那行产生错误的代码应该被删除。
您在找getRef()
吗?会:
databaseReference = adapter.getRef(position);
在这种情况下,我强烈建议保留您正在使用的类的源代码,因为整个FirebaseAdapter.java
文件只有47行长,可以快速帮助您找到做了和不存在的。