setadapter,因为该适配器是FireStoreRecycleServiceAdapter

ulydmbyx  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(370)

这是一个Notes应用程序,它从firebase数据库获取数据,并通过自己的适配器firestorerecycleradapter显示数据,以便在recycler视图中查看。一切都是正确的,但错误是,当我为recyclerview设置Adapter时,它会显示以下错误-
setadapter(androidx.recyclerview.widget.recyclerview.adapter)位于
无法将androidx.recyclerview.widget.recyclerview'应用于
(com.firebase.ui.firestore.firestorerecycleradapter)'
行内**mrecyclerview.setadapter(noteadapter)

public class notes_Activity extends AppCompatActivity {
    FloatingActionButton mcreatesnote;
    private FirebaseAuth firebaseAuth;
    FirebaseUser firebaseUser;
    FirebaseFirestore firebaseFirestore;

    RecyclerView mrecyclerView;
    StaggeredGridLayoutManager staggeredGridLayoutManager;

  FirestoreRecyclerAdapter<firebasemodel,NoteViewHolder> noteadapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notes);
        getSupportActionBar().setTitle("All Notes");
        firebaseAuth= FirebaseAuth.getInstance();
        firebaseUser= FirebaseAuth.getInstance().getCurrentUser();
        firebaseFirestore= FirebaseFirestore.getInstance();

        mcreatesnote= findViewById(R.id.createsnote);
        mcreatesnote.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(notes_Activity.this, Create_note_activity.class));
            }
        });

        Query query= firebaseFirestore.collection("notes").document(firebaseUser.getUid()).collection("myNotes").orderBy("title",Query.Direction.ASCENDING);

        FirestoreRecyclerOptions<firebasemodel> allusernotes= new FirestoreRecyclerOptions.Builder<firebasemodel>().setQuery(query,firebasemodel.class).build();

        noteadapter= new FirestoreRecyclerAdapter<firebasemodel, NoteViewHolder >(allusernotes) {
            @Override
            protected void onBindViewHolder(@NonNull NoteViewHolder noteviewholder, int i, @NonNull firebasemodel firebasemodel) {

                noteviewholder.notetitle.setText(firebasemodel.getTitle());
                noteviewholder.notecontent.setText(firebasemodel.getContent());

            }

            @NonNull
            @Override
            public NoteViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.notes_layout,parent,false);
                return new NoteViewHolder(view);

            }
        };
        mrecyclerView= findViewById(R.id.recyclerview);
        mrecyclerView.setHasFixedSize(true);
        staggeredGridLayoutManager= new 
        StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
        mrecyclerView.setLayoutManager(staggeredGridLayoutManager);

        mrecyclerView.setAdapter(noteadapter);

    }
    public class NoteViewHolder extends android.support.v7.widget.RecyclerView.ViewHolder
        {
        private TextView notetitle;
        private TextView notecontent;
        LinearLayout mnote;

        public NoteViewHolder(View itemView) {
            super(itemView);
            notetitle= itemView.findViewById(R.id.note_title);
            notecontent= itemView.findViewById(R.id.note_content);
            mnote= itemView.findViewById(R.id.note);
        }
    }

        @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu,menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId())
        {
            case R.id.logout: firebaseAuth.signOut();
            finish();
            startActivity(new Intent(notes_Activity.this, MainActivity.class));
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onStart() {
        super.onStart();
        noteadapter.startListening();
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (noteadapter!=null)
        {
            noteadapter.stopListening();
        }
    }
}

错误是-

'setAdapter(androidx.recyclerview.widget.RecyclerView.Adapter)' in     
androidx.recyclerview.widget.RecyclerView' cannot be applied to     
(com.firebase.ui.firestore.FirestoreRecyclerAdapter)'

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题