How to use get getApplicationContext() in Adapter Class

后端 未结 3 1353
长情又很酷
长情又很酷 2020-12-07 06:16

I am using Firebase to populate my BlogRecycleadapter with blog post and get Likes from Like Buttons but when device is offline and user press Like Button , then app crashes

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 07:02

    Try this

    You can pass Context in your Constructor of your BlogRecyclerAdapter

    public BlogRecyclerAdapter(List < BlogPost > blog_list, Context context) {
    
        this.blog_list = blog_list;
        this.context = context;
    
     }
    

    use like this

    firebaseFirestore = FirebaseFirestore.getInstance(context);
    firebaseAuth = FirebaseAuth.getInstance(context);
    
    
    
    Glide.with(context).applyDefaultRequestOptions(placeholderOption).load(image).into(blogUserImage);
    

    call your BlogRecyclerAdapter like this

    BlogRecyclerAdapter adapter= new BlogRecyclerAdapter( blog_list, YourActivity.this );
    

提交回复
热议问题