Firebase Database search query issue - java

I'm trying to create a search feature where users can search other registered. i managed to get the search to work but its not giving the desired result. No matter what keyword i input, it brings up all the registered users on the search result instead of just the ones related to the keyword.
i'm no expert in java but ive tried changing and rearranging some lines, but the outcome is still the same.
private void SearchPeopleAndFriends(String searchBoxInput)
{
FirebaseRecyclerOptions<FindFriends> options = new FirebaseRecyclerOptions.Builder<FindFriends>().
setQuery(UsersRef, FindFriends.class).build(); //query build past the query to FirebaseRecyclerAdapter
FirebaseRecyclerAdapter<FindFriends, FindFriendsActivity.FindFriendViewHolder> adapter=new FirebaseRecyclerAdapter<FindFriends, FindFriendViewHolder>(options)
{
#Override
protected void onBindViewHolder(#NonNull FindFriendsActivity.FindFriendViewHolder holder, int position, #NonNull FindFriends model)
{
holder.username.setText(model.getFullname());
holder.status.setText(model.getStatus());
Picasso.get().load(model.getProfileimage()).into(holder.profileimage);
holder.itemView.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent findOthersIntent = new Intent(FindFriendsActivity.this, FindFriendsActivity.class);
startActivity(findOthersIntent);
}
});
}
#NonNull
#Override
public FindFriendsActivity.FindFriendViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i)
{
View view= LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.all_user_display_layout,viewGroup,false);
FindFriendsActivity.FindFriendViewHolder viewHolder=new FindFriendsActivity.FindFriendViewHolder(view);
return viewHolder;
}
};
SearchResultList.setAdapter(adapter);
adapter.startListening();
}
public class FindFriendViewHolder extends RecyclerView.ViewHolder
{
TextView username, status;
CircleImageView profileimage;
public FindFriendViewHolder(#NonNull View itemView)
{
super(itemView);
username = itemView.findViewById(R.id.all_user_profile_name);
status = itemView.findViewById(R.id.all_user_status);
profileimage = itemView.findViewById(R.id.all_user_profile_pic);
}
}
Instead of it bringing user related to the keyword in the search result, it brings up all the users in the database. my goal is for it to only display whatever users name contains the keyword that was inputed
This is my model class
public class FindFriends {
public String profileimage, fullname, status;
public FindFriends()
{
}
public String getProfileimage() {
return profileimage;
}
public void setProfileimage(String profileimage) {
this.profileimage = profileimage;
}
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public FindFriends(String profileimage, String fullname, String status) {
this.profileimage = profileimage;
this.fullname = fullname;
this.status = status;
}
}
My Firebase Refs:
mAuth = FirebaseAuth.getInstance();
currentUserID = mAuth.getCurrentUser().getUid();
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users");

Related

When i retrive children from firebase using recylceview TextView Won't Show

I'm using Android Studio when I run my app and add or show RecycleView list, text view shows only the title not data inside firebase this is the textviewaddCateogryclass
What would be causing this?
used the same data on firebase child.
firebase realtime database
Firebase
ModelCategoryClass
public class ModelCategoryClass {
//same variable in db
String id, category, uid;
long timestamp;
public ModelCategoryClass() {}
public ModelCategoryClass(String id, String category, String uid, long timestamp) {
this.id = id;
this.category = category;
this.uid = uid;
this.timestamp = timestamp;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
}
AdapterCategoryClass
public class AdapterCategoryClass extends RecyclerView.Adapter<AdapterCategoryClass.HolderCategory> {
private Context context;
private ArrayList<ModelCategoryClass> categoryClassArrayList;
//xml rows_categorys
private RowsCategorysBinding binding;
//constucor
public AdapterCategoryClass(Context context, ArrayList<ModelCategoryClass> categoryClassArrayList) {
this.context = context;
this.categoryClassArrayList = categoryClassArrayList;
}
///////////////
//generated from RecyclerView.Adapter<AdapterCategoryClass.HolderCategory>
#NonNull
#Override
public HolderCategory onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
//binding
binding = RowsCategorysBinding.inflate(LayoutInflater.from(context), parent, false);
return new HolderCategory(binding.getRoot());
//return new HolderCategory(RowsCategorysBinding.inflate(LayoutInflater.from(parent.getContext()),parent,false));
}
//getting data
#Override
public void onBindViewHolder(#NonNull HolderCategory holder, int position) {
ModelCategoryClass model = categoryClassArrayList.get(position);
String id = model.getId();
String category = model.getId();
String uid = model.getId();
long timestamp = model.getTimestamp();
//remove btn
//as we declred remove btn in HolderCatogory method
holder.removeBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(context,""+category,Toast.LENGTH_SHORT).show();
}
});
}
#Override
public int getItemCount() {
return categoryClassArrayList.size();
}
/////////////
//hold lists xml
public class HolderCategory extends RecyclerView.ViewHolder {
TextView textViewListCatt;
ImageButton removeBtn;
//constu
public HolderCategory(#NonNull View itemView) {
super(itemView);
textViewListCatt = binding.textViewListCat;
removeBtn = binding.removeBtn;
}
}
}
CategoryAddActivity class
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityCategoryAddBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
//init firebase auth
firebaseAuth = FirebaseAuth.getInstance();
ShowCategories();
private void ShowCategories() {
categoryClassArrayList = new ArrayList<>();
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("Categories");
ref.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
//clear array befor add data
categoryClassArrayList.clear();
for (DataSnapshot dataSnapshot : snapshot.getChildren()) {
//get data from child in database
ModelCategoryClass mod = dataSnapshot.getValue(ModelCategoryClass.class);
//add data to array
categoryClassArrayList.add(mod);
}
//start using adapter
adapterCategoryClass = new AdapterCategoryClass(CategoryAddActivity.this, categoryClassArrayList);
//get recycleListview rom xml and set it with defualt set method
binding.recycleList.setAdapter(adapterCategoryClass);
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
}
The following lines of code:
ModelCategoryClass model = categoryClassArrayList.get(position);
String id = model.getId();
String category = model.getId();
String uid = model.getId();
long timestamp = model.getTimestamp();
Should be changed to:
ModelCategoryClass model = categoryClassArrayList.get(position);
String id = model.getId();
String category = model.getCategory(); //👈
String uid = model.getUid(); //👈
long timestamp = model.getTimestamp();
Meaning that you need to call the corresponding getters. But that's not the entire problem. You aren't displaying something because you aren't setting those values to their corresponding views. To solve this, you have to create inside your HolderCategory class a method that actually binds the data to the views. For example, to set the category, you should use something like this:
void setCategory(String category) {
binding.textViewListCat.setText(category);
}
And then call this method from inside your onBindViewHolder method like this:
holder.setCategory(category);

I want to display User data from Firebase to RecyclerView

I want to retrieve data from Firebase to recyclerView through FirebaseRecyclerOptionsbut it keeps showing blanks pages,I want to display the registered Users in my App and there details in a layout,I have no idea where I have gone wrong,I have multi check on my codes and I can't see any error Please can Anyone help me here.
Here Are Code for ListAdapter,Model and ListActivity
public class ListActivity extends AppCompatActivity {
private FirebaseAuth firebaseAuth;
private DatabaseReference reference;
RecyclerView recyclerView;
ListAdapter listAdapter;
private String CurrentUserID;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
recyclerView = findViewById(R.id.children_home_list);
firebaseAuth = FirebaseAuth.getInstance();
CurrentUserID = firebaseAuth.getCurrentUser().getUid();
reference = FirebaseDatabase.getInstance().getReference().child("Children Home Details");
recyclerView.setLayoutManager(new LinearLayoutManager(this));
FirebaseRecyclerOptions<Model> options =
new FirebaseRecyclerOptions.Builder<Model>()
.setQuery(reference, Model.class)
.build();
listAdapter = new ListAdapter(options);
}
#Override
protected void onStart() {
super.onStart();
listAdapter.startListening();
}
#Override
protected void onStop() {
super.onStop();
listAdapter.stopListening();
}
public class ListAdapter extends FirebaseRecyclerAdapter<Model,ListAdapter.ListViewHolder> {
public ListAdapter(#NonNull FirebaseRecyclerOptions<Model> options) {
super(options);
}
#Override
protected void onBindViewHolder(#NonNull ListViewHolder holder, int position, #NonNull Model model) {
holder.Name.setText(model.getName());
holder.Phone.setText(model.getPhone());
holder.Location.setText(model.getLocation());
holder.Email.setText(model.getMailAddress());
//Glide.with(holder.circleImageView.getContext()).load(model.IMAGELINK()).into(holder.circleImageView);
}
#NonNull
#Override
public ListViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.singlerow,parent,false);
return new ListViewHolder(view);
}
class ListViewHolder extends RecyclerView.ViewHolder {
CircleImageView circleImageView;
TextView Name,Phone,Email,Location;
public ListViewHolder(#NonNull View itemView) {
super(itemView);
circleImageView = itemView.findViewById(R.id.img1);
Name = itemView.findViewById(R.id.HomeName);
Phone = itemView.findViewById(R.id.phoneName);
Email = itemView.findViewById(R.id.paypalAddress);
Location = itemView.findViewById(R.id.location);
}
}
}
public class Model {
String Name,Phone,Location,MailAddress;
public Model(String name, String phone, String location, String mailAddress) {
Name = name;
Phone = phone;
Location = location;
MailAddress = mailAddress;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getPhone() {
return Phone;
}
public void setPhone(String phone) {
Phone = phone;
}
public String getLocation() {
return Location;
}
public void setLocation(String location) {
Location = location;
}
public String getMailAddress() {
return MailAddress;
}
public void setMailAddress(String mailAddress) {
MailAddress = mailAddress;
}
}

getting null Value from firestore to recycleview

I have made Notificatiion Activity that getting the data from Cloud Firestore. After I test the app. I got always null from database, I checked in the debug. I found the data is read from database, but not setting it in Notification.java. Here is my code:
NotificationActivity.java:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notifications);
getSupportActionBar().setTitle(R.string.menu_notifications);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
initRecyclerView();
getNotifications();
Adview();
}
private void initRecyclerView() {
Log.d(TAG, "initRecyclerView: init recyclerview.");
mRecyclerView = findViewById(R.id.recyclerv_view);
if (mNotificationsAdapter == null) {
mNotificationsAdapter = new NotificationsAdapter(this, mNotifications);
}
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(mNotificationsAdapter);
}
private void getNotifications() {
SharedPreferences prefs = getSharedPreferences("TOKEN_PREF", MODE_PRIVATE);
String token = prefs.getString("token", "");
FirebaseFirestore db = FirebaseFirestore.getInstance();
CollectionReference notificationsCollectionRef = db.collection("notifications").document(token).collection("messages");
Query query = notificationsCollectionRef
.orderBy("Date", Query.Direction.DESCENDING);
query.get().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Notifications notifications = document.toObject(Notifications.class);
mNotifications.add(notifications);
}
mNotificationsAdapter.notifyDataSetChanged();
} else {
Log.d(TAG,"Query Failed. Check Logs.");
}
});
}
NotificationsAdapter.java:
class NotificationsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final String TAG = "NotificationsAdapter";
private ArrayList<Notifications> mNotifications;
private Context mContext;
public NotificationsAdapter(Context context, ArrayList<Notifications> notifications) {
mNotifications = notifications;
mContext = context;
}
#NonNull
#Override
public RecyclerView.ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
RecyclerView.ViewHolder holder;
View view = LayoutInflater.from(parent.getContext()).inflate(
R.layout.notifications_listitem, parent, false);
holder = new ViewHolder(view);
return holder;
}
#Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
Log.d(TAG, "onBindViewHolder: called.");
if (holder instanceof ViewHolder) {
((ViewHolder) holder).title.setText(mNotifications.get(position).getTitle());
((ViewHolder) holder).message.setText(mNotifications.get(position).getMessage());
((ViewHolder) holder).date_time.setText(mNotifications.get(position).getDate() + "\n" + mNotifications.get(position).getTime());
((ViewHolder) holder).parentLayout.setOnClickListener(view -> {
Log.d(TAG, "onClick: clicked on: " + mNotifications.get(position).getTitle());
Intent intent = new Intent(mContext, NotificationDetails.class);
// intent.putExtra("image_url", mImages.get(position));
intent.putExtra("shop_name", mNotifications.get(position).getTitle());
intent.putExtra("message", mNotifications.get(position).getMessage());
mContext.startActivity(intent);
});
}
}
#Override
public int getItemCount() {
return mNotifications.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
CircleImageView image;
TextView title, message, date_time;
RelativeLayout parentLayout;
public ViewHolder(View itemView) {
super(itemView);
image = itemView.findViewById(R.id.shop_image);
title = itemView.findViewById(R.id.title);
message = itemView.findViewById(R.id.message);
date_time = itemView.findViewById(R.id.date_time);
parentLayout = itemView.findViewById(R.id.parent_layout);
}
}
Notifications.java
#IgnoreExtraProperties
public class Notifications {
private String title;
private String message;
private String date;
private String time;
public Notifications() {
}
public Notifications(String title, String message, String date, String time) {
this.title = title;
this.message = message;
this.date = date;
this.time = time;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}
Make sure your Firestore / firebase attributes and you java/Kotlin data class attributes are the same. I mean caps letters and everything.
Call the getNotification() method first.
I solved the issue by changing the variables in the model class to be starting with capital letter.

I cannot retrieve my data from Firebase Database using my FirebaseRecyclerAdapter

After adding my data to the firebase real-time database, it got updated successfully. Then I wanted to get all the data I added to show in my main activity. After writing the code which I've appended below, I was not seeing any syntax error but if I ran the app I don't seem to get my data to view on my main activity and I can't seem to figure out the error. If anyone could help me, I will be grateful. Thank you all.
This is my model.
package com.example.myapplication.Activities;
public class Posts {
public String date, description,fullName,postImage,profileImage,time,uid;
public Posts(){
}
public Posts(String date, String description, String fullName, String postImage, String profileImage, String time, String uid) {
this.date = date;
this.description = description;
this.fullName = fullName;
this.postImage = postImage;
this.profileImage = profileImage;
this.time = time;
this.uid = uid;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getPostImage() {
return postImage;
}
public void setPostImage(String postImage) {
this.postImage = postImage;
}
public String getProfileImage() {
return profileImage;
}
public void setProfileImage(String profileImage) {
this.profileImage = profileImage;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
}
This is my query
private DatabaseReference databaseReference, postRef;
databaseReference = FirebaseDatabase.getInstance().getReference().child("users");
postRef = FirebaseDatabase.getInstance().getReference().child("posts");
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.Maintoolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Home");
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
LinearLayoutManager linearLayoutManager = new
LinearLayoutManager(this);
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(linearLayoutManager);
displayAllUserPosts();
}
Using the FirebaseRecyclerAdapter
private void displayAllUserPosts() {
FirebaseRecyclerOptions<Posts> options =
new FirebaseRecyclerOptions.Builder<Posts>()
.setQuery(postRef, Posts.class)
.build();
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Posts, PostViewHolder>(options) {
#Override
protected void onBindViewHolder(#NonNull PostViewHolder postViewHolder, int i, #NonNull Posts posts) {
postViewHolder.setDate(posts.getDate());
postViewHolder.setDescription(posts.getDescription());
postViewHolder.setFullName(posts.getFullName());
postViewHolder.setTime(posts.getTime());
postViewHolder.setPostImage(getApplicationContext(),posts.getPostImage());
postViewHolder.setProfileImage(getApplicationContext(), posts.getProfileImage());
}
#NonNull
#Override
public PostViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.all_post_layout, parent, false);
return new PostViewHolder(view);
}
};
recyclerView.setAdapter(firebaseRecyclerAdapter);
}
public static class PostViewHolder extends RecyclerView.ViewHolder{
View view;
public PostViewHolder(#NonNull View itemView) {
super(itemView);
view = itemView;
}
public void setFullName(String fullName){
TextView username = (TextView) view.findViewById(R.id.post_user_name);
username.setText(fullName);
}
public void setProfileImage(Context context, String profileImage){
CircleImageView profileimage = (CircleImageView) view.findViewById(R.id.post_profile_image);
Picasso.with(context).load(profileImage).into(profileimage);
}
public void setDate( String date) {
TextView Date = (TextView)view.findViewById(R.id.post_date);
Date.setText(" " + date);
}
public void setTime(String time) {
TextView Time = (TextView)view.findViewById(R.id.post_time);
Time.setText(" " + time);
}
public void setDescription(String description) {
TextView Description = (TextView)view.findViewById(R.id.post_description);
Description.setText(description);
}
public void setPostImage( Context context, String postImage){
ImageView postimage = (ImageView)view.findViewById(R.id.post_image);
Picasso.with(context).load(postImage).into(postimage);
}
}
This is my database tree
posts
gjZxz9HL4IblUAcdWz788Z9AdXu118
May
202023:44
date:
"18/May/2020"
description:
"my first"
fullName:
"emeka"
postImage:
"https://firebasestorage.googleapis.com/v0/b/soc..."
profileImage:
"https://firebasestorage.googleapis.com/v0/b/soc..."
time:
"23:44"
uid:
"gjZxz9HL4IblUAcdWz788Z9AdXu1"
gjZxz9HL4IblUAcdWz788Z9AdXu120
May
2020:00:55
date:
"20/May/2020"
description:
"I like this"
fullName:
"emeka"
postImage:
"https://firebasestorage.googleapis.com/v0/b/soc..."
profileImage:
"https://firebasestorage.googleapis.com/v0/b/soc..."
time:
":00:55"
uid:
"gjZxz9HL4IblUAcdWz788Z9AdXu1"
Please, if anyone can, help me. I will be grateful. Thank you.
this is what I get when I run the app, the image below
enter image description here
I found the answer I was using addOnCompleteListener to get the Download URL for my post image instead of addOnSuccesslistener

How to Retrieve Value in RecyclerView I tried a lot but it Retrieve a Null Value from Generated ID by Firebase after Push Data in Database in Android

How to retrieve value in RecyclerView I tried a lot but it retrieve a null value from generated id by Firebase after push data in database and if I don't using this method "push" the data stored in second id directly and retrieved well in Android and in log cat:
W/ClassMapper: No setter/field for -L9VWgoCymRWj9zbgK5H [image for database stracture][1]
This is my code:
public class TasksListActivity extends AppCompatActivity {
RecyclerView recyclerView;
TaskAdapter adapter;
List<Tasks>tasksList;
FirebaseDatabase FDB;
DatabaseReference DBR;
private FirebaseAuth mAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tasks_list);
recyclerView=(RecyclerView) findViewById(R.id.testingss);
RecyclerView.LayoutManager manager=new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(manager);
recyclerView.setHasFixedSize(true);
mAuth = FirebaseAuth.getInstance();
tasksList=new ArrayList<>();
adapter=new TaskAdapter(tasksList);
FDB=FirebaseDatabase.getInstance();
GetDataFirebase();
}
void GetDataFirebase (){
FirebaseUser currentUser = mAuth.getCurrentUser();
final String currentid=currentUser.getUid();
DBR=FDB.getReference("tasks").child(currentid);
DBR.addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Tasks data=dataSnapshot.getValue(Tasks.class);
//Toast.makeText(getApplicationContext(),tas,Toast.LENGTH_SHORT).show();
tasksList.add(data);
adapter.notifyDataSetChanged();
recyclerView.setAdapter(adapter);
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
public class TaskAdapter extends RecyclerView.Adapter<TaskAdapter.TaskViewHolder>{
List<Tasks> data=new ArrayList<>();
public TaskAdapter(List<Tasks> tasks){
this.data=tasks;
}
#Override
public TaskAdapter.TaskViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.taskslistitem,parent,false);
return new TaskViewHolder(view);
}
#Override
public void onBindViewHolder(TaskAdapter.TaskViewHolder holder, int position) {
Tasks tasks=data.get(position);
holder.taskName.setText(tasks.getmTaskname());
Toast.makeText(getApplicationContext(),tasks.getmTaskname(),Toast.LENGTH_SHORT).show();
//Toast.makeText(getApplication(),tasks.getmTaskname(),Toast.LENGTH_SHORT).show();
// Toast.makeText(getApplicationContext(),holder.taskName.getText(),Toast.LENGTH_SHORT).show();
}
#Override
public int getItemCount() {
return data.size();
}
public class TaskViewHolder extends RecyclerView.ViewHolder {
TextView taskName;
public TaskViewHolder(View itemView) {
super(itemView);
taskName=(TextView) itemView.findViewById(R.id.tasksnameId);
}
}
}
}
the class about tasks model
public class Tasks {
private String mMemberEmail;
private String mTaskname;
private String mTaskDsc;
private String mTaskDeadline;
public Tasks() {
}
public Tasks(String mMemberEmail, String mTaskname, String mTaskDsc, String mTaskDeadline) {
this.mMemberEmail = mMemberEmail;
this.mTaskname = mTaskname;
this.mTaskDsc = mTaskDsc;
this.mTaskDeadline = mTaskDeadline;
}
public String getmMemberEmail() {
return mMemberEmail;
}
public void setmMemberEmail(String mMemberEmail) {
this.mMemberEmail = mMemberEmail;
}
public String getmTaskname() {
return mTaskname;
}
public void setmTaskname(String mTaskname) {
this.mTaskname = mTaskname;
}
public String getmTaskDsc() {
return mTaskDsc;
}
public void setmTaskDsc(String mTaskDsc) {
this.mTaskDsc = mTaskDsc;
}
public String getmTaskDeadline() {
return mTaskDeadline;
}
public void setmTaskDeadline(String mTaskDeadline) {
this.mTaskDeadline = mTaskDeadline;
}
}
final Tasks tasks=new Tasks(mMemberEmail,mTasksName,mTaskDsc,mTaskDeadline);
mUserDatabase.child("tasks").child(current_id).child(id).push().setValue(tasks).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
String current_id = user.getUid();
Tasks tasks=new Tasks(mMemberEmail,mTasksName,mTaskDsc,mTaskDeadline);
String id = child.getKey();
mUserDatabase.child("tasks").child(id).child(current_id).push().setValue(tasks);
}
});
}
You are getting the following warning:
W/ClassMapper: No setter/field for -L9VWgoCymRWj9zbgK5H
Because you are using wrong getters for your fields. The correct getter for a field that looks like this:
private String mMemberEmail;
Should be:
public String getMMemberEmail() { //See the first capital M
return mMemberEmail;
}
The correct naming for the fields and getters inside a model should be:
public class Tasks {
private String memberEmail;
private String taskName;
private String taskDsc;
private String taskDeadline;
public Tasks() {}
public Tasks(String memberEmail, String taskName, String taskDsc, String taskDeadline) {
this.memberEmail = memberEmail;
this.taskName = taskName;
this.taskDsc = taskDsc;
this.taskDeadline = taskDeadline;
}
public String getMemberEmail() {return memberEmail;}
public String getTaskName() {return taskName;}
public String getTaskDsc() {return taskDsc;}
public String getTaskDeadline() {return taskDeadline;}
}
So remember, when the Firebase Realtime Database SDK deserializes objects coming from the database, is looking for fields that follow the principles of the JavaBeans and are named accordingly to Java Naming Conventions. So the corresponding getter for a field like memberEmail is getMemberEmail() and not getmemberEmail(). To make it work entirely, delete old data and add fresh one.

Categories