Output not showing when the firebase ui upgrade to 3.2.2 - android

When i upgrade my firebase-ui version to 3.2.2 the firebaserecycleradapter doesn't show any output the code of mine. at first when i got multidex error then i upgrade all library version to lastest version on dependency of app lvl gradle and after upgrade the problem is found the Firebaserecycleradapter method then i search it and write after run the app the list view are not displaying plz help me.
onStart():
#Override
protected void onStart() {
super.onStart();
FirebaseRecyclerOptions <Users> options = new FirebaseRecyclerOptions.Builder<Users>()
.setQuery(mUserDatabase,Users.class)
.build();
FirebaseRecyclerAdapter<Users, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(options) {
#NonNull
#Override
public UsersViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.user_list_layout, parent, false);
return new UsersViewHolder(view);
}
#Override
protected void onBindViewHolder(#NonNull UsersViewHolder holder, int position, #NonNull Users model) {
holder.setName(model.getName());
holder.setStatus(model.getStatus());
holder.setRIDNo(model.getRidno());
holder.setUserImage(model.getThumb_image(), getApplicationContext());
//to get key
final String user_id = getRef(position).getKey();
holder.mView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent profileIntent = new Intent(UsersActivity.this, ProfileActivity.class);
profileIntent.putExtra("user_id", user_id);
startActivity(profileIntent);
}
});
}
};
mUsersList.setAdapter(firebaseRecyclerAdapter);
}
and the viewholder is:
//User list viewholder
public static class UsersViewHolder extends RecyclerView.ViewHolder {
static View mView;
private CircleImageView mUserView;
public UsersViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public static void setName(String name){
TextView userNameView = (TextView) mView.findViewById(R.id.user_single_name);
userNameView.setText(name);
}
public static void setStatus(String status){
TextView userStatusView = (TextView) mView.findViewById(R.id.user_single_status);
userStatusView.setText(status);
}
public static void setRIDNo(String ridno){
TextView userRIDNoView = (TextView) mView.findViewById(R.id.user_single_ridno);
userRIDNoView.setText(ridno);
}
public static void setUserImage(String thumb_image, Context ctx){
CircleImageView userImageView = (CircleImageView) mView.findViewById(R.id.user_single_image);
Picasso.with(ctx).load(thumb_image).placeholder(R.drawable.default_avatar).into(userImageView);
}
}

In order to make your code work, please consider using the following steps.
Remove the static from the declaration of your UsersViewHolder class. Should be only:
public class UsersViewHolder extends RecyclerView.ViewHolder {/* ... */}
Remove the static keyword also from the mView field and all your methods. Your holder class should look like this:
public class UsersViewHolder extends RecyclerView.ViewHolder {
private View mView;
private CircleImageView mUserView;
public UsersViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setName(String name){
TextView userNameView = (TextView) mView.findViewById(R.id.user_single_name);
userNameView.setText(name);
}
public void setStatus(String status){
TextView userStatusView = (TextView) mView.findViewById(R.id.user_single_status);
userStatusView.setText(status);
}
public void setRIDNo(String ridno){
TextView userRIDNoView = (TextView) mView.findViewById(R.id.user_single_ridno);
userRIDNoView.setText(ridno);
}
public void setUserImage(String thumb_image, Context ctx){
CircleImageView userImageView = (CircleImageView) mView.findViewById(R.id.user_single_image);
Picasso.with(ctx).load(thumb_image).placeholder(R.drawable.default_avatar).into(userImageView);
}
}
Move all the code from the onStart() method inside onCreate() method except this line of code:
super.onStart();
Make your firebaseRecyclerAdapter varaible global:
private FirebaseRecyclerAdapter<Users, UsersViewHolder> firebaseRecyclerAdapter;
Remove FirebaseRecyclerAdapter<Blog, BlogViewHolder> from the onCreate() method.
Add the following lines of code in the onStart() and onStop() methods.
#Override
protected void onStart() {
super.onStart();
firebaseRecyclerAdapter.startListening();
}
#Override
protected void onStop() {
super.onStop();
if(firebaseRecyclerAdapter != null) {
firebaseRecyclerAdapter.stopListening();
}
}
If you are using authentication, please also don't forget to add this line of code inside onStart() method:
firebaseAuth.addAuthStateListener(authStateListener);

Related

NullPointerException at FirebaseRecyclerAdapter.startListening()

I've got a problem with my app. I am trying to show all my user's list and their details (status, phone number), but I keep on getting the null pointer exception error on the onStart method. Here is my code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_customer_status);
...
}
#Override
protected void onStart() {
super.onStart();
firebaseRecyclerAdapter.startListening();
options =
new FirebaseRecyclerOptions.Builder<Users>()
.setQuery(mUserDbase, Users.class)
.build();
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(options) {
#NonNull
#Override
public UsersViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.activity_customer_status, parent, false);
return new UsersViewHolder(view);
}
#Override
protected void onBindViewHolder(#NonNull UsersViewHolder usersViewHolder, int i, #NonNull Users users) {
usersViewHolder.setName(users.getName());
usersViewHolder.setPhone(users.getPhone());
usersViewHolder.setStatus(users.getStatus());
}
};
mUserList.setAdapter(firebaseRecyclerAdapter);
}
#Override
protected void onStop() {
super.onStop();
firebaseRecyclerAdapter.stopListening();
}
// View Holder Class
public static class UsersViewHolder extends RecyclerView.ViewHolder{
View mView;
public UsersViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setName (String name){
TextView userNameView = (TextView) mView.findViewById(R.id.name_text);
userNameView.setText(name);
}
public void setPhone (String phone){
TextView userNameView = (TextView) mView.findViewById(R.id.phone_text);
userNameView.setText(phone);
}
public void setStatus (String status){
TextView userNameView = (TextView) mView.findViewById(R.id.status_text);
userNameView.setText(status);
}
}
}
I've followed this question: Error in FirebaseListAdapter.startListening(), which explains that the activity life cycle works as (onCreate>onStart>onResume), so assuming that (i'm a newb) I placed my on start code above my firebaseRecyclerAdapter. I've also followed this question as a guide but it didn't help me either. Please help
You are using the pointer firebaseRecyclerAdapter before initializing it.
firebaseRecyclerAdapter = new FirebaseRecyclerAdapte(){...};
firebaseRecyclerAdapter.startListening();
mUserList.setAdapter(firebaseRecyclerAdapter);

setItemOnclickListener not working in FirebaseRecyclerAdapter

Im new to FirebASE and Stuck on setItemclickListener , here are some snippets shown please help me. Mainly struck in the FirebaseRecycler where the setItemClickListener is the interface and used for Onclick of the Firebaserecy
Leavereqests.java
#Override
//LeaveReqests.java
leavereq= database.getReference("LeafForm");
recyclerview = (RecyclerView)findViewById(R.id.recycler_hod);
recyclerview.setHasFixedSize(true);
LinearLayoutManager manager = new LinearLayoutManager(this);
recyclerview.setLayoutManager(manager);
loadhod();
}
private void loadhod() {
adapter = new FirebaseRecyclerAdapter<LeaveReq, HodViewHolder>(LeaveReq.class,R.layout.hod_login_list
,HodViewHolder.class,leavereq) {
#Override
protected void populateViewHolder(HodViewHolder viewHolder, LeaveReq model, int position) {
viewHolder.name.setText(model.getName());
clickitem = model;
viewHolder.setItemClickListener(new ItemClickListener() { //the non working part
#Override
public void onClick(View view, int position) {
Intent hodlist = new Intent(LeaveRequests.this,HodReqList.class);
hodlist.putExtra("hodid",adapter.getRef(position).getKey());
startActivity(hodlist);
}
});
}
};
recyclerview.setAdapter(adapter);}}
HodViewholder.java
public class HodViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public Button name;
private ItemClickListener itemClickListener;
public HodViewHolder(View itemView) {
super(itemView);
name=(Button)itemView.findViewById(R.id.name_of_faculty);
itemView.setOnClickListener(this);
}
public void setItemClickListener(ItemClickListener itemClickListener) {
this.itemClickListener = itemClickListener;
}
#Override
public void onClick(View view) {
itemClickListener.onClick(view,getAdapterPosition(),false);
}}
LeaveReq.java is the class which has getter of the name.
public class LeaveReq {
private String name;
public LeaveReq() {
}
public LeaveReq(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Item Click Listener Interface
public interface ItemClickListener {
void onClick(View view, int position);
}
the list is being populated but the click action is not working
Try something like that
The functions such as the RecycleView buttons should be placed into the HodViewHolder class so that the RecycleView can identify the tools that are clicked by the button
//public static class ViewHolder extends RecyclerView.ViewHolder {..
View mView;
//public ViewHolder(View itemView) {...
super(itemView);
mView = itemView;
viewHolder.mView .setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {....}
I hope to help you..
#Override
protected void onStart() {
super.onStart();
FirebaseRecyclerAdapter<adapter, PandaViewHolder> MyAdapter = new FirebaseRecyclerAdapter <adapter, PandaViewHolder>(
adapter.class,
R.layout.replay_panda,
HodViewHolder.class,
mDatabase
) {
#Override
protected void populateViewHolder(final PandaViewHolder viewHolder, adapter model, int position) {
final String position_key = getRef( position ).getKey().toString();
viewHolder.setTitle(model.getTitle());
//// Here
//#################################
viewHolder.mView.setOnClik{....}
//#################################
}
};
RecyclerView.setAdapter( MyAdapter );
}
public static class HodViewHolder extends RecyclerView.ViewHolder {
View mView;
DatabaseReference mDatabase1231223;
FirebaseAuth mAuth;
public PandaViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
// post text view
public void setTitle(String title) {
}

Can't find what's wrong in onBindViewHolder in FirebaseRecyclerAdapter Class

I'm trying to display an image and three textViews in recyclerView using Firebase but all i'm getting is a blank page. I'm thinking there's something wrong with the onBindViewHolder method, but i can't seem to find what.
onCreate
mFoodList=(RecyclerView)findViewById(R.id.foodList);
mFoodList.setHasFixedSize(true);
mFoodList.setLayoutManager(new LinearLayoutManager(this));
mDatabase= FirebaseDatabase.getInstance().getReference().child("Item");
mQuery=mDatabase.orderByKey();
mOptions=new FirebaseRecyclerOptions.Builder<Food>().setQuery(mQuery, Food.class).build();
mAuth=FirebaseAuth.getInstance();
mAuthListener=new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
if(firebaseAuth.getCurrentUser()==null){
Intent loginIntent=new Intent(MenuActivity.this,MainActivity.class);
loginIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(loginIntent);
}
}
};
onStart - This is where i'm having problems.
#Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
FBRA = new FirebaseRecyclerAdapter<Food, FoodViewHolder>(mOptions) {
#Override
protected void onBindViewHolder(#NonNull FoodViewHolder viewHolder, int position, #NonNull Food model) {
viewHolder.setName(model.getName());
viewHolder.setPrice(model.getPrice());
viewHolder.setDesc(model.getDesc());
viewHolder.setImage(getApplicationContext(),model.getImage());
}
#Override
public FoodViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.singlemenuitem, parent, false);
return new FoodViewHolder(view);
}
};
mFoodList.setAdapter(FBRA);
}
FoodViewHolder
public static class FoodViewHolder extends RecyclerView.ViewHolder{
View mView;
public FoodViewHolder(View itemView) {
super(itemView);
mView=itemView;
}
public void setName(String name){
TextView food_name=(TextView)mView.findViewById(R.id.foodName);
food_name.setText(name);
}
public void setPrice(String price){
TextView food_price=(TextView)mView.findViewById(R.id.foodPrice);
food_price.setText(price);
}
public void setDesc(String desc){
TextView food_desc=(TextView)mView.findViewById(R.id.foodDesc);
food_desc.setText(desc);
}
public void setImage(Context ctx, String image){
ImageView food_image=(ImageView)mView.findViewById(R.id.foodImage);
Picasso.with(ctx).load(image).into(food_image);
}
}
Unless you're using FirebaseRecyclerOptions.Builder#setLifecycleOwner(this), you'll have to manually call FirebaseRecyclerAdapter#[start/stop]Listening(). I would recommend reading the documentation.
As said by SUPERCILEX, you are using FirebaseRecyclerOption.Builder,
so you need to manually start and stop FirebaseRecyclerView listening.
So put Onstart()
mFoodList.startListening();
and OnStop()
mFoodList.stopListening();

Adding new image on the top of recyclerview

I am trying to show the new updates on the top. I am using firebase and recyclerview.
#Override
protected void onStart() {
super.onStart();
FirebaseRecyclerAdapter<Feed,FeedViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Feed, FeedViewHolder>(
Feed.class,R.layout.news_feed_row,FeedViewHolder.class,mDatabase
) {
#Override
protected void populateViewHolder(FeedViewHolder viewHolder, Feed model, int position) {
viewHolder.setdesc(model.getDesc());
viewHolder.setimage(getApplicationContext(),model.getImage());
}
};
mNews_Feed_list.setAdapter(firebaseRecyclerAdapter);
}
public static class FeedViewHolder extends RecyclerView.ViewHolder{
View mView;
public FeedViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setdesc(String desc){
TextView post_desc_value = (TextView) mView.findViewById(R.id.post_desc_card_view);
post_desc_value.setText(desc);
}
public void setimage(final Context ctx, final String image){
final ImageView post_image = (ImageView) mView.findViewById(R.id.post_image_card_view);
Glide.with(ctx).load(image).diskCacheStrategy(DiskCacheStrategy.ALL).into(post_image);
}
}
Add this method to your adapter and call it to add new item to the recycler view
public void addItem(Feed model){
<your list name>.add(0, model);
notifyItemInserted(0);
mRecyclerView.smoothScrollToPosition(0);
}

How to Pass TextView text from Recyclerview to other Activity in Android

I created a simple application which contain RecyclerView TextView and Images loaded from the Firebase.
Now I want to pass the text from TextView to other activity.
The TextView is in RecyclerView:
The code:
FirebaseRecyclerAdapter<Blog,BlogViewHolder> firebaseRecyclerAdapter=new
FirebaseRecyclerAdapter<Blog, BlogViewHolder>(
Blog.class,
R.layout.blog_row,
BlogViewHolder.class,
mDatabase
) {
#Override
protected void populateViewHolder(final BlogViewHolder viewHolder,
Blog model, final int position) {
final String post_keyy=getRef(position).getKey();
viewHolder.setTitle(model.getTitle());
viewHolder.setDesc(model.getDesc());
viewHolder.setImag(getApplicationContext(),model.getImage());
}
};
mBlogList.setAdapter(firebaseRecyclerAdapter);
}
public static class BlogViewHolder extends RecyclerView.ViewHolder
{
View mView;
TextView post_title,post_desc;
ImageView post_imge;
public BlogViewHolder(View itemView) {
super(itemView);
mView=itemView;
}
public void setTitle(String title)
{
post_title=(TextView)mView.findViewById(R.id.posttitle);
post_title.setText(title);
}
public void setDesc(String desc)
{
post_desc=(TextView)mView.findViewById(R.id.post_desc);
post_desc.setText(desc);
}
public void setImag(Context ctx,String image)
{
post_imge=(ImageView) mView.findViewById(R.id.postimg);
Picasso.with(ctx).load(image).into(post_imge);
}
}
Now I want to pass post_title textview text to other activity.
You should try to add the onClickListener in the onBindViewHolder method of your RecyclerAdapter class:
#Override
public void onBindViewHolder(BlogViewHolder holder, int position) {
//Set the OnClickListener on whatever view you want to trigger when clicked.
holder.mView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//You can get the context from the view itself.
Intent intent = new Intent(view.getContext(), theOtherActivityName.class);
//Put your intent extras.
intent.putExtra("blog_id",post_title.getText().toString());
view.getContext().startActivity(intent);
}
});
}

Categories

Resources