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
Related
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 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;
}
}
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'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");
Sorry if i m asking lame questions i m new to android development.
I have a activity in which i m populating firebase recycler adapter problem is that it is not populating recycler (loadFoodlist) when i click on that activity once.
But when i click that activity twice or thrice after that it is getting data perfectly fine i don't know what is the problem it happens whenever i relaunch the app?
Database structure
database image
public class FoodDetailModel {
String name, price, description, type;
public FoodDetailModel(){
}
public FoodDetailModel(String name, String price, String description, String type) {
this.name = name;
this.price = price;
this.description = description;
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
public class FoodDetailViewHolder extends RecyclerView.ViewHolder {
public TextView foodname,price,description;
public Button delete;
public ImageView type;
public FoodDetailViewHolder(#NonNull View itemView) {
super(itemView);
foodname = (TextView) itemView.findViewById(R.id.food_name);
price = (TextView) itemView.findViewById(R.id.food_price);
description = (TextView) itemView.findViewById(R.id.food_description);
delete = (Button) itemView.findViewById(R.id.add_to_cart);
type = itemView.findViewById(R.id.type);
}
}
public class FoodDetail extends AppCompatActivity {
FirebaseDatabase database;
FirebaseAuth mAuth;
DatabaseReference ref;
FirebaseRecyclerAdapter<FoodDetailModel, FoodDetailViewHolder> adapter;
RecyclerView recycler_menu;
RecyclerView.LayoutManager layoutManager;
CollapsingToolbarLayout collapsingToolbarLayout;
ProgressDialog dialog1 ;
String resID = "", resName = "";
ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_food_detail);
dialog1 = new ProgressDialog(FoodDetail.this);
mAuth = FirebaseAuth.getInstance();
imageView = (ImageView) findViewById(R.id.food_img);
if(getIntent() != null){
resID = getIntent().getStringExtra("restraunt_id");
resName = getIntent().getStringExtra("name");
}
// init firebase
collapsingToolbarLayout = findViewById(R.id.collapsing);
collapsingToolbarLayout.setExpandedTitleTextAppearance(R.style.ExpandedAppBar);
collapsingToolbarLayout.setCollapsedTitleTextAppearance(R.style.CollapsedAppBar);
collapsingToolbarLayout.setTitle(resName);
// load restuarant list from firebase
recycler_menu = (RecyclerView) findViewById(R.id.foodmenu_list);
recycler_menu.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recycler_menu.setLayoutManager(layoutManager);
loadFoodList();
loadName();
}
private void loadName() {
DatabaseReference ref1 = FirebaseDatabase.getInstance().getReference();
DatabaseReference mostafa = ref1.child("restaurant").child(resID).child("img");
mostafa.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
String imgURL = dataSnapshot.getValue(String.class);
Picasso.with(getBaseContext()).load(imgURL).fit().into(imageView);
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
private void loadFoodList() {
ref = FirebaseDatabase.getInstance().getReference().child("menu").child(resID);
System.out.println("getttts here" + ref.toString());
adapter = new FirebaseRecyclerAdapter<FoodDetailModel, FoodDetailViewHolder>
(FoodDetailModel.class,R.layout.food_detail_blueprint, FoodDetailViewHolder.class,ref) {
#Override
protected void populateViewHolder(final FoodDetailViewHolder viewHolder, final FoodDetailModel model, final int position) {
final String x = adapter.getRef(position).toString();
viewHolder.foodname.setText(model.getName());
viewHolder.price.setText("₹"+model.getPrice());
viewHolder.description.setText(model.getDescription());
String typ = model.getType();
if (typ.equals("veg")){
viewHolder.type.setImageResource(R.drawable.veg);
} else {
viewHolder.type.setImageResource(R.drawable.nonveg);
}
viewHolder.delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final AlertDialog.Builder alert = new AlertDialog.Builder(FoodDetail.this);
alert.setTitle("Delete entry");
alert.setMessage("Are you sure you want to delete?");
alert.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// close dialog
dialog.cancel();
}
});
alert.show();
}
});
}
};
recycler_menu.setAdapter(adapter);
}
}