我在我的android项目中使用firebase“FirebaseRecyclerAdapter”没有更新依赖项我添加了旧依赖但没有工作

时间:2018-02-18 05:30:29

标签: java android firebase firebase-realtime-database firebaseui

我想从Firebase for android中检索数据。但它不起作用。请帮助我,我完全困惑或建议我容易理解的例子。我处于初级水平。我正确查看所有代码没有一个错误。 FirebaseRecyclerAdapter没有更新的依赖项。

public class MainActivity extends AppCompatActivity {
StorageReference storageReference ;
RecyclerView recyclerView;

private DatabaseReference databaseReference_my;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    recyclerView=findViewById(R.id.blog_list);
    storageReference= FirebaseStorage.getInstance().getReference();
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));

    databaseReference_my= FirebaseDatabase.getInstance().getReference().child("blog");
}

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

    FirebaseRecyclerAdapter<Blog, BlogViewHolder> firebaseRecyclerAdapter =new FirebaseRecyclerAdapter<Blog, BlogViewHolder>(
            Blog.class,
            R.layout.blog_row,
            BlogViewHolder.class,
            databaseReference_my

    ) {
        @Override
        protected void populateViewHolder(BlogViewHolder viewHolder, Blog model, int position) {
            viewHolder.setTitle(model.getTitle());
            viewHolder.setDetail(model.getTitle());

        }
    };
    recyclerView.setAdapter(firebaseRecyclerAdapter);
}

public static class BlogViewHolder extends RecyclerView.ViewHolder
{

    View view;

    public BlogViewHolder(View itemView) {
        super(itemView);
        view=itemView;
    }

    public  void setTitle(String title)
    {
        TextView put_title=view.findViewById(R.id.coming_title);
        put_title.setText(title);
    }
    public void setDetail(String detail)
    {
        TextView put_detail=view.findViewById(R.id.coming_detail);
        put_detail.setText(detail);
    }
}

1 个答案:

答案 0 :(得分:0)

use following: build.gradle(app level)
    compile 'com.firebase:firebase-client-android:2.4.0'
    compile 'com.firebaseui:firebase-ui-storage:1.0.1'
    compile 'com.firebaseui:firebase-ui-database:1.0.1'