从Firebase获取数据到Recycler视图

时间:2018-05-15 04:24:48

标签: android firebase firebase-realtime-database

我正在开发一个应用程序,它将来自firebase数据库的数据提取到回收站视图中。但数据没有被提取。

这是代码:

else if (getArguments().getInt(ARG_SECTION_NUMBER) == 2) {
                rootView = inflater.inflate(R.layout.fragment_street_food, container, false);
                final String[] dateee = new String[1];
                myRef1 = FirebaseDatabase.getInstance().getReference().child("Video_Upload").child("Street");
                rView = (RecyclerView) rootView.findViewById(R.id.StreetRecyclerView);
                RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
                rView.setLayoutManager(layoutManager);
                FirebaseRecyclerAdapter<StreetDataFetcher, Street_food.StreetViewHolder> FBRA = new FirebaseRecyclerAdapter<StreetDataFetcher, Street_food.StreetViewHolder>(
                        StreetDataFetcher.class,
                        R.layout.card_recycler_view,
                        Street_food.StreetViewHolder.class,
                        myRef1
                ) {
                    @Override
                    protected void populateViewHolder( Street_food.StreetViewHolder viewHolder, StreetDataFetcher model, int position ) {
                        viewHolder.setTitle(model.getVideoName());
                        viewHolder.setShortDesc(model.getShort_Desc());
                        viewHolder.setUsername(model.getUserName());
                        //viewHolder.setDate(model.getDateTime());
                    }
                };

                rView.setAdapter(FBRA);
                return rootView;
            }

StreetViewHolder.class

class StreetViewHolder extends RecyclerView.ViewHolder
    {
        TextView Username;
        TextView datee;
        TextView Title;
        TextView ShortDesc;
        public StreetViewHolder( View itemView ) {
            super(itemView);
            Username=(TextView)itemView.findViewById(R.id.UsernameText);
            datee=(TextView)itemView.findViewById(R.id.date);
            Title=(TextView)itemView.findViewById(R.id.Title);
            ShortDesc=(TextView)itemView.findViewById(R.id.ShortDescription);
        }

        public void setTitle( String title ) {
            Title.setText(title);
        }


        public void setShortDesc( String shortDesc ) {
            ShortDesc.setText(shortDesc);
        }

        public void setUsername( String username ) {
            Username.setText(username);
        }


        public void setDate( String date ) {
            datee.setText(date);
        }
    }

StreetDataFetcher

public class StreetDataFetcher {

    String UserName, VideoName, VideoPath, Long_Desc, Short_Desc, DateTime;
    int Likes, Views;

    public StreetDataFetcher( String userName, String videoName, String videoPath, String long_Desc, String short_Desc, String dateTime, int likes, int views ) {
        UserName = userName;
        VideoName = videoName;
        VideoPath = videoPath;
        Long_Desc = long_Desc;
        Short_Desc = short_Desc;
        DateTime = dateTime;
        Likes = likes;
        Views = views;
    }

    public StreetDataFetcher() {
    }

    public String getUserName() {
        return UserName;
    }

    public void setUserName( String userName ) {
        UserName = userName;
    }

    public String getVideoName() {
        return VideoName;
    }

    public void setVideoName( String videoName ) {
        VideoName = videoName;
    }

    public String getVideoPath() {
        return VideoPath;
    }

    public void setVideoPath( String videoPath ) {
        VideoPath = videoPath;
    }

    public String getLong_Desc() {
        return Long_Desc;
    }

    public void setLong_Desc( String long_Desc ) {
        Long_Desc = long_Desc;
    }

    public String getShort_Desc() {
        return Short_Desc;
    }

    public void setShort_Desc( String short_Desc ) {
        Short_Desc = short_Desc;
    }

    public String getDateTime() {
        return DateTime;
    }

    public void setDateTime( String dateTime ) {
        DateTime = dateTime;
    }

    public int getLikes() {
        return Likes;
    }

    public void setLikes( int likes ) {
        Likes = likes;
    }

    public int getViews() {
        return Views;
    }

    public void setViews( int views ) {
        Views = views;
    }
}

我的firebase结构如下所示:

this is the picture of firebase Database root

数据未在回收站视图中获取,并且也不存在错误。

0 个答案:

没有答案