FireBaseRecyclerAdapterの問題.. setQueryが参照とクラスを使用してメソッドを解決できないと通知するのはなぜですか?

GoldNerd:

ここで私はあなたに私のフラグメントの両方のコードを貼り付けました+ Posts.classなぜこれが私にエラーを表示するのか誰にも分かりますか?私はこれが初めてなので、自分でそれを理解することは本当にできません。

FirebaseRecyclerOptions<Posts> option = 
    new FirebaseRecyclerOptions.Builder<Posts>()
            .setQuery(postsRef, Posts.class).build();

コードフラグメント

package com.LiFit;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.Query;

import de.hdodenhof.circleimageview.CircleImageView;

public class HomeFragment extends Fragment {

    View myFragment;
    private ImageButton postButton;
    private RecyclerView postlist;
    CollectionReference postsRef;
    FirebaseFirestore db;


    public static ProfileFragment getInstance() {
        return new ProfileFragment();
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        myFragment = inflater.inflate(R.layout.fragment_home, container, false);
        postButton = myFragment.findViewById( R.id.postButton);
        postlist = myFragment.findViewById(R.id.postlist);
        postlist.setHasFixedSize(true);
        LinearLayoutManager lmManager = new LinearLayoutManager(getActivity());
        lmManager.setReverseLayout(true);
        lmManager.setStackFromEnd(true);
        postlist.setLayoutManager(lmManager);
        db = FirebaseFirestore.getInstance();
        postsRef = db.collection("posts");
        postButton.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SendUserToPostActivity();
            }
        } );

        DisplayAllUsersPosts();
        return myFragment;
    }

    private void DisplayAllUsersPosts() {
        FirebaseRecyclerOptions<Posts> option = new FirebaseRecyclerOptions.Builder<Posts>().setQuery(postsRef, Posts.class).build();

        FirebaseRecyclerAdapter<Posts, PostsViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Posts, PostsViewHolder>(option) {
            @Override
            protected void onBindViewHolder(@NonNull PostsViewHolder holder, int position, @NonNull Posts model) {

            }

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

    public static class PostsViewHolder extends RecyclerView.ViewHolder{
        View mView;
        TextView username, postTime, postDescription;
        CircleImageView profileImage;
        ImageView postImage;
        public PostsViewHolder(@NonNull View itemView) {
            super(itemView);
            mView=itemView;
            username = mView.findViewById(R.id.post_userName);
            postTime = mView.findViewById(R.id.post_uploadTime);
            postDescription = mView.findViewById(R.id.post_description);
            profileImage = mView.findViewById(R.id.post_profileImage);
            postImage = mView.findViewById(R.id.post_image);
        }
    }

    private void SendUserToPostActivity() {
        Intent postIntent = new Intent(getActivity(), PostActivity.class);
        startActivity(postIntent);
    }
}

Posts.class

package com.LiFit;

public class Posts {
    public String description, picture, postType, profileImage, time, uid, username;

    public Posts(){

    }

    public Posts(String description, String picture, String postType, String profileImage, String time, String uid, String username) {
        this.description = description;
        this.picture = picture;
        this.postType = postType;
        this.profileImage = profileImage;
        this.time = time;
        this.uid = uid;
        this.username = username;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getPicture() {
        return picture;
    }

    public void setPicture(String picture) {
        this.picture = picture;
    }

    public String getPostType() {
        return postType;
    }

    public void setPostType(String postType) {
        this.postType = postType;
    }

    public String getProfileImage() {
        return profileImage;
    }

    public void setProfileImage(String profileImage) {
        this.profileImage = profileImage;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
}
Tomoko Sugi :

私はおそらくあなたと同じ問題に遭遇しました。使用しているのはRealtime Databaseではなく、Firestoreですよね?以下で修正しました。

アプリbuild.gradle

// before
implementation 'com.firebaseui:firebase-ui-database: 6.2.1'

// after
implementation 'com.firebaseui:firebase-ui-firestore:6.2.1'

ソース:

// before
import com.firebase.ui.database.FirebaseRecyclerOptions;

// after
import com.firebase.ui.firestore.FirestoreRecyclerOptions;

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ