无法解析“FirebaseRecyclerOptions”中的方法“getCurrentList”

2fjabf4q  于 2023-04-07  发布在  其他
关注(0)|答案(2)|浏览(104)

我正在开发一个大学搜索应用程序,我无法解决这个错误。
代码如下:

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库,但是我不得不改变我的整个代码。我还能做什么?

zc0qhyus

zc0qhyus1#

您的adapter对象是一个FirebaseRecyclerPagingAdapter类型的对象。当您尝试在这样的对象上调用getCurrentList(position)时,预期的行为是获得以下错误:

Cannot resolve method 'getCurrentList' in 'FirebaseRecyclerOptions':101

因为适配器类中没有getCurrentList()方法。此外,如果存在这样的方法,正如其名称所示,它将返回一个列表而不是DatabaseReference对象。因此,查看您的代码,应删除产生该错误的代码行。

j91ykkif

j91ykkif2#

你在找getRef()吗?那就是:

databaseReference = adapter.getRef(position);

在这种情况下,我强烈建议您将正在使用的类的源代码放在手边,因为整个FirebaseAdapter.java file只有47行,可以快速帮助您找到 * 存在 * 和 * 不存在 *。

相关问题