无法应用FirebaseRecyclerAdapter?

时间:2018-01-20 20:25:43

标签: android firebase firebase-realtime-database firebaseui

这是我的MainActivity代码

package com.proj.hex.hoop;

import android.content.Context;
import android.content.Intent;
import android.media.Image;
import android.support.annotation.NonNull;
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.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.squareup.picasso.Picasso;

public class MainActivity extends AppCompatActivity {

    private RecyclerView mBlogList;
    private DatabaseReference mRef;
    private FirebaseRecyclerAdapter<Blog, BlogViewHolder> mrecyclerAdapter;

    private FirebaseAuth mAuth;
    private FirebaseAuth.AuthStateListener mAuthListener;
//Created on 18/1/2018 Faiz

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);




        mAuth = FirebaseAuth.getInstance();
        mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {

                if (firebaseAuth.getCurrentUser() == null){

                    Intent loginIntent = new Intent(MainActivity.this, Registration.class);
                    loginIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(loginIntent);

                }

            }
        };

        mRef = FirebaseDatabase.getInstance().getReference();


        mBlogList = (RecyclerView) findViewById(R.id.blog_list);
        mBlogList.setHasFixedSize(true);
        mBlogList.setLayoutManager(new LinearLayoutManager(this));

        FirebaseRecyclerOptions<Blog> options;
        options = new FirebaseRecyclerOptions.Builder<Blog>()
                .setQuery(mRef, Blog.class)
                .build();

        FirebaseRecyclerOptions<BlogViewHolder> options1;
        options1 = new FirebaseRecyclerOptions.Builder<BlogViewHolder>()
                .setQuery(mRef, BlogViewHolder.class)
                .build();



            }


    @Override
            protected void onStart(){
                super.onStart();


        mAuth.addAuthStateListener(mAuthListener);


        FirebaseRecyclerAdapter<Blog, BlogViewHolder> adapter = new FirebaseRecyclerAdapter<Blog, BlogViewHolder>(
                Blog.class,
                BlogViewHolder.class,
                R.layout.blog_row,
                mRef)
        {
            @Override
            protected void onBindViewHolder(@NonNull BlogViewHolder holder, int position, @NonNull Blog model) {

                holder.setTitle(model.getTitle());
                holder.setDesc(model.getDesc());
                holder.setImage(getApplicationContext(), model.getImage());

            }

            @Override
            public BlogViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                return null;
            }

            protected  void populateViewHolder(BlogViewHolder viewHolder, Blog model, int position){

                viewHolder.setTitle(model.getTitle());
                viewHolder.setDesc(model.getDesc());
                viewHolder.setImage(getApplicationContext(), model.getImage());
            }

        };
        mBlogList.setAdapter(adapter);


    }

        public static class BlogViewHolder extends RecyclerView.ViewHolder{

        View mView;

        public BlogViewHolder(View itemView) {
            super(itemView);

            mView = itemView;


        }

        public void setTitle(String title){

            TextView post_title = (TextView) mView.findViewById(R.id.post_title);
            post_title.setText(title);

        }

        public void setDesc(String Desc){

            TextView post_des = (TextView) mView.findViewById(R.id.post_desc);
            post_des.setText(Desc);
        }
        public void setImage(Context ctx, String image){

            ImageView post_image = (ImageView) mView.findViewById(R.id.post_img);
            Picasso.with(ctx).load(image).into(post_image);
        }
    }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.action_add) {
            startActivity(new Intent(MainActivity.this, PostActivity.class));


        }

        if (item.getItemId() == R.id.action_logout){


            logout();
        }
        return super.onOptionsItemSelected(item);
    }


    private void logout() {
enter code here
                mAuth.signOut();

    }


}

所以请帮我解决我的问题

  

FirebaseRecyclerAdapter中的FirebaseRecyclerAdapter()不能   适用于:预期参数:实际参数:选项:   COM ... com.proj.hex.hoop.Blog&GT;   Blog.class(java.lang.Class中)

     

BlogViewHolder.class(java的... hoop.MainActivity.BlogViewHolder&GT)

     

R.layout.blog_row(int)的

     

MREF(COM ... firebase.database.DatabaseReference)“

     

在FirebaseRecycleAdapter

0 个答案:

没有答案