I have the same code for another database and it works just fine, I have no Idea why it's not working here,
the onCreateViewHolder does not even get called.
(Appearently Stacks Overflow wants me to add more details to compensate for too much code so here's some unuseful Text , Text, Text , TEXT).
public class Course extends AppCompatActivity {
private RecyclerView mLocationView;
private DatabaseReference mLocation;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_course);
mLocation = FirebaseDatabase.getInstance().getReference("FINISHEDCOURSES");
mLocation.keepSynced(true);
mLocationView = (RecyclerView) findViewById(R.id.my_recycler_view);
mLocationView.setHasFixedSize(true);
mLocationView.setLayoutManager(new LinearLayoutManager(this));
}
#Override
protected void onStart() {
super.onStart();
FirebaseRecyclerOptions<Courses> options = new FirebaseRecyclerOptions.Builder<Courses>().setQuery(mLocation, Courses.class).build();
FirebaseRecyclerAdapter<Courses, CourseViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Courses, CourseViewHolder>
(options) {
#Override
protected void onBindViewHolder(#NonNull CourseViewHolder holder, int position, #NonNull Courses model) {
holder.setText(model.getDate(), model.getDistance(), model.getDriver(), model.getPrice());
}
#NonNull
#Override
public CourseViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.courses_rows, parent, false);
return new CourseViewHolder(view);
}
};
mLocationView.setAdapter(firebaseRecyclerAdapter);
firebaseRecyclerAdapter.startListening();
}
public static class CourseViewHolder extends RecyclerView.ViewHolder{
View mView;
public CourseViewHolder(View itemView){
super(itemView);
mView = itemView;
}
public void setText(String Date, String start, String end, String price){
TextView dateText = mView.findViewById(R.id.dateText);
TextView startText = mView.findViewById(R.id.depart_text);
TextView endText = mView.findViewById(R.id.end_text);
TextView priceText = mView.findViewById(R.id.price);
dateText.setText(Date);
startText.setText(start);
endText.setText(end);
priceText.setText(price);
}
}
The Courses Class
public class Courses {
private String driver, date, distance, preWaitTime, price, waitTime, client;
public Courses() {
}
public Courses(String driver, String date, String distance, String preWaitTime, String price, String waitTime, String client) {
this.driver = driver;
this.date = date;
this.distance = distance;
this.preWaitTime = preWaitTime;
this.price = price;
this.waitTime = waitTime;
this.client = client;
}
public String getDriver() {
return driver;
}
public void setDriver(String driver) {
this.driver = driver;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getDistance() {
return distance;
}
public void setDistance(String distance) {
this.distance = distance;
}
public String getPreWaitTime() {
return preWaitTime;
}
public void setPreWaitTime(String preWaitTime) {
this.preWaitTime = preWaitTime;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getWaitTime() {
return waitTime;
}
public void setWaitTime(String waitTime) {
this.waitTime = waitTime;
}
public String getClient() {
return client;
}
public void setClient(String client) {
this.client = client;
}
}
Here's The Database Structure :
Sorry I should have commented but i do not have enough reputation to do so.
I cannot see anything similar to this in your code.
FirebaseRecyclerAdapter<Courses, CourseViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Courses, CourseViewHolder>(
Courses.class,
R.layout.Courses,// should be your layout name
CourseViewHolder.class,
mLocation
) {
#Override
protected void populateViewHolder(CourseViewHolder viewHolder, category model, final int position) {
viewHolder.setName(model.getName());
viewHolder.setImage(getApplicationContext(),model.getImage());
Related
Guys i'm trying to build App like Instagram. I'm struck to fetch the data from the Firebase database and storage. The recyclerView is showing nothing. Help me out in fixing that.
all the data are store in Firebase database.
Recyclerview Adapter page in the fragment page
ProgressBar proBar;
private FirebaseAuth.AuthStateListener authStateListener;
Context context;
String cuurentUser;
FirebaseAuth firebaseAuth;
FirebaseRecyclerAdapter adapter;
RecyclerView recyclerView;
List<Post> postingList;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_reviews, container, false);
PostAdapter postAdapter = new PostAdapter(context, postingList);
recyclerView = view.findViewById(R.id.recycView);
proBar = view.findViewById(R.id.proBar);
recyclerView.setHasFixedSize(true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(postAdapter);
postAdapter.notifyDataSetChanged();
firebaseAuth = FirebaseAuth.getInstance();
cuurentUser = firebaseAuth.getCurrentUser().getUid();
getDetails();
return view;
}
private void getDetails() {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
Query query = FirebaseDatabase.getInstance().getReference().child("Posts").child(cuurentUser);
FirebaseRecyclerOptions<Post> options = new FirebaseRecyclerOptions.Builder<Post>()
.setQuery(query, new SnapshotParser<Post>() {
#NonNull
#Override
public Post parseSnapshot(#NonNull DataSnapshot snapshot) {
return new Post(snapshot.child("id").getValue().toString(),
snapshot.child("profileImg").getValue().toString(),
snapshot.child("username").getValue().toString(),
snapshot.child("postImg").getValue().toString(),
snapshot.child("description").getValue().toString(),
snapshot.child("time").getValue().toString(),
snapshot.child("date").getValue().toString(),
snapshot.child("title").getValue().toString()
);
}
})
.build();
adapter = new FirebaseRecyclerAdapter<Post, PostViewHolder>(options) {
#NonNull
#Override
public PostViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.post_item, parent, false);
//PostViewHolder viewHolder = new PostViewHolder(view);
return new PostViewHolder(view);
}
#Override
protected void onBindViewHolder(#NonNull final PostViewHolder holder, final int position, #NonNull final Post model) {
// String uid = getRef(position).getKey();
holder.uname.setText(model.getUsername());
holder.descrip.setText(model.getDescription());
holder.ptime.setText(model.getTime());
holder.pdate.setText(model.getDate());
holder.ptitle.setText(model.getTitle());
Glide.with(getContext()).load(model.getProfileImg()).into(holder.profImg);
Glide.with(getContext()).load(model.getPostImg()).into(holder.postImage);
holder.linear.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, String.valueOf(position), Toast.LENGTH_SHORT).show();
}
});
}
};
recyclerView.setAdapter(adapter);
}
}, 2000);
}
#Override
public void onStart() {
super.onStart();
if(postingList != null)
adapter.startListening();
}
#Override
public void onStop() {
super.onStop();
adapter.stopListening();
}
public static class PostViewHolder extends RecyclerView.ViewHolder {
TextView uname, fname, descrip, ptime, pdate, ptitle;
CircleImageView profImg;
ImageView postImage;
View mview;
LinearLayout linear;
public PostViewHolder(#NonNull View itemView) {
super(itemView);
mview = itemView;
linear = itemView.findViewById(R.id.linearRoot);
uname = itemView.findViewById(R.id.username);
fname = itemView.findViewById(R.id.fullname);
descrip = itemView.findViewById(R.id.description);
ptime = itemView.findViewById(R.id.ptime);
pdate = itemView.findViewById(R.id.pdate);
ptitle = itemView.findViewById(R.id.ptitle);
profImg = itemView.findViewById(R.id.profImg);
postImage = itemView.findViewById(R.id.postImg);
}
}
model page as Post.java
public class Post implements Parcelable {
public Post() {
}
private String uid;
private String postImg;
private String description;
private String username;
private String date;
private String time;
private String profileImg;
private String title;
public Post(String uid, String postImg, String description, String username, String date, String time, String profileImg, String title) {
this.uid = uid;
this.postImg = postImg;
this.description = description;
this.username = username;
this.date = date;
this.time = time;
this.profileImg = profileImg;
this.title = title;
}
protected Post(Parcel in) {
uid = in.readString();
postImg = in.readString();
description = in.readString();
username = in.readString();
date = in.readString();
time = in.readString();
profileImg = in.readString();
title = in.readString();
}
public static final Creator<Post> CREATOR = new Creator<Post>() {
#Override
public Post createFromParcel(Parcel in) {
return new Post(in);
}
#Override
public Post[] newArray(int size) {
return new Post[size];
}
};
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getPostImg() {
return postImg;
}
public void setPostImg(String postImg) {
this.postImg = postImg;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
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;
}
public String getProfileImg() {
return profileImg;
}
public void setProfileImg(String profileImg) {
this.profileImg = profileImg;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(uid);
dest.writeString(postImg);
dest.writeString(description);
dest.writeString(username);
dest.writeString(date);
dest.writeString(time);
dest.writeString(profileImg);
dest.writeString(title);
}
}
xml page with recyclerView
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TabLayout.ReviewsFragment">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/recycView"
/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/proBar"/>
</FrameLayout>
Another xml page to show the details is post_item.xml
The last time I was working on my app, it was working fine as expected. After a month of not working on it, it doesn't pop out the layout as shown when I was last working on it. When I click the button, it will just lead to a blank page
Adapter
public class RestaurantAdapter extends FirebaseRecyclerAdapter<RestaurantDetails,RestaurantAdapter.RestaurantViewHolder> {
public RestaurantAdapter(#NonNull FirebaseRecyclerOptions<RestaurantDetails> options) {
super(options);
}
FirebaseRecyclerOptions<RestaurantDetails> options =
new FirebaseRecyclerOptions.Builder<RestaurantDetails>()
.setQuery(FirebaseDatabase.getInstance().getReference().child("Restaurant").child("Info"), RestaurantDetails.class)
.build();
#Override
protected void onBindViewHolder(#NonNull RestaurantViewHolder holder, final int position, #NonNull final RestaurantDetails details) {
holder.restaurant_Name.setText(details.getName());
holder.restaurant_Category.setText(details.getCategory());
holder.restaurant_Location.setText(details.getLocation());
Picasso.get().load(details.getImage()).into(holder.restaurant_Image);
holder.itemView.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
String post_key = getRef(position).getKey();
Intent intent = new Intent(view.getContext(), RestaurantInfoActivity.class);
intent.putExtra("post_key", post_key);
view.getContext().startActivity(intent);
}
});
}
#NonNull
#Override
public RestaurantViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view =LayoutInflater.from(parent.getContext())
.inflate(R.layout.restaurant_list,parent, false);
return new RestaurantViewHolder(view);
}
class RestaurantViewHolder extends RecyclerView.ViewHolder{
TextView restaurant_Name, restaurant_Category,restaurant_Location;
ImageView restaurant_Image;
public RestaurantViewHolder(#NonNull View itemView){
super(itemView);
restaurant_Name = itemView.findViewById(R.id.restaurant_Name);
restaurant_Category = itemView.findViewById(R.id.restaurant_Category);
restaurant_Location = itemView.findViewById(R.id.restaurant_Location);
restaurant_Image = itemView.findViewById(R.id.restaurant_Image);
}
}
}
ResRecyclerViewActivity
public class ResRecyclerViewActivity extends AppCompatActivity {
private static final String TAG = "ResRecyclerViewActivity";
private RecyclerView restaurantRecyclerView;
private RestaurantAdapter adapter;
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_restaurantlist);
Log.d(TAG, "onCreate: started.");
restaurantRecyclerView = findViewById(R.id.restaurant_rv);
restaurantRecyclerView.setLayoutManager(new LinearLayoutManager(this));
FirebaseRecyclerOptions<RestaurantDetails> options =
new FirebaseRecyclerOptions.Builder<RestaurantDetails>()
.setQuery(FirebaseDatabase.getInstance().getReference().child("Restaurant").child("Info"), RestaurantDetails.class)
.build();
adapter = new RestaurantAdapter(options);
restaurantRecyclerView.setAdapter(adapter);
}
#Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
#Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
}
RestaurantDetails (Model)
public class RestaurantDetails {
private String name;
private String location;
private String address;
private String category;
private String image;
private Double latitude;
private Double longitude;
public RestaurantDetails(String name, String location, String address, String category, String image, Double latitude, Double longitude) {
this.name = name;
this.location = location;
this.address = address;
this.category = category;
this.image = image;
this.latitude = latitude;
this.longitude = longitude;
}
public RestaurantDetails() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImage() {
return image;
}
public void setImage(String image) { this.image = image; }
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public Double getLatitude() {return latitude;}
public void setLatitude(Double lang) {this.latitude = latitude;}
public Double getLongitude() {return longitude;}
public void setLongitude(Double longitude) {this.longitude = longitude;}
}
When I debug the app,this are the comments that pop up. No errors were shown
It might be due to firebase rules. Check your firebase database rules because after a month firebase rules changed to default for security reasons.
i have facing issue like only two items are displayed others two items are not displayed they are contact and flat no this items are not displaying...i tried also removing and adding others textview but through this only two items are displayed.... Now I want to display the data on a RecyclerView which doesn't seem to work, I'm pretty sure that my code is good but something doesn't seem to work and I can't find it.i also try all the things suggested by stackoverflow but nothing can happen so that i think i need to ask...
Here the file
public class RecieptFP extends AppCompatActivity {
private RecyclerView mFirestoreList;
private FirebaseFirestore firebasefirestore;
private FirestoreRecyclerAdapter adapter;
Button Back;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reciept_fp);
Back = findViewById(R.id.btndashboard);
firebasefirestore = FirebaseFirestore.getInstance();
mFirestoreList = findViewById(R.id.firestore_list);
//query
Query query = firebasefirestore.collection("UserDataR");
//RecyclerOptions
FirestoreRecyclerOptions<RecieptModel> options = new FirestoreRecyclerOptions.Builder<RecieptModel>()
.setQuery(query, RecieptModel.class)
.build();
adapter = new FirestoreRecyclerAdapter<RecieptModel, RecieptViewHolder>(options) {
#NonNull
#Override
public RecieptViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listsingleiteam, parent, false);
return new RecieptViewHolder(view);
}
#Override
protected void onBindViewHolder(RecieptViewHolder recieptViewHolder, int i, RecieptModel recieptModel) {
recieptViewHolder.list_name.setText(recieptModel.getName());
recieptViewHolder.list_amount.setText(recieptModel.getAmount());
recieptViewHolder.list_contact.setText(recieptModel.getContact());
recieptViewHolder.list_Flatno.setText(recieptModel.getFlatNo());
}
};
//viewholder
mFirestoreList.setHasFixedSize(false);
mFirestoreList.setLayoutManager(new LinearLayoutManager(this));
mFirestoreList.setAdapter(adapter);
Back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i1 = new Intent(RecieptFP.this, Dashboard.class);
startActivity(i1);
}
});
}
private class RecieptViewHolder extends RecyclerView.ViewHolder {
private TextView list_name;
private TextView list_amount;
private TextView list_contact;
private TextView list_Flatno;
public RecieptViewHolder(#NonNull View itemView) {
super(itemView);
list_name = itemView.findViewById(R.id.list_name);
list_amount = itemView.findViewById(R.id.list_amount);
list_contact = itemView.findViewById(R.id.list_contact);
list_Flatno = itemView.findViewById(R.id.list_Flatno);
}
}
#Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
#Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
}
Recipet Model
package com.societypay;
public class RecieptModel {
private String Name;
private String Amount;
private String Contact;
private String FlatNo;
private RecieptModel(){}
private RecieptModel(String Name,String Amount,String Contact,String FlatNo){
this.Name=Name;
this.Amount=Amount;
this.Contact=Contact;
this.FlatNo=FlatNo;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getAmount() {
return Amount;
}
public void setAmount(String amount) {
Amount = amount;
}
public String getContact() {
return Contact;
}
public void setContact(String contact) {
Contact = contact;
}
public String getFlatNo() {
return FlatNo;
}
public void setFlatNo(String flatNo) {
FlatNo = flatNo;
}
}
Please use following pojo and try.
public class RecieptModel
{
private String MobileNo;
private String Amount;
private String Flat_no;
private String Name;
public String getMobileNo ()
{
return MobileNo;
}
public void setMobileNo (String MobileNo)
{
this.MobileNo = MobileNo;
}
public String getAmount ()
{
return Amount;
}
public void setAmount (String Amount)
{
this.Amount = Amount;
}
public String getFlat_no ()
{
return Flat_no;
}
public void setFlat_no (String Flat_no)
{
this.Flat_no = Flat_no;
}
public String getName ()
{
return Name;
}
public void setName (String Name)
{
this.Name = Name;
}
#Override
public String toString()
{
return "ClassPojo [MobileNo = "+MobileNo+", Amount = "+Amount+", Flat_no = "+Flat_no+", Name = "+Name+"]";
}
}
I'm still relatively new to Android and firebase and trying to populate recyclerview from firebase database but for some reasons that I can't get, the view is not populated.The activity loads but all I see is a blank activity page.I'd like to populate these views using data from a Firebase Database just to get three data(name,email,phonenos) of Users.
public class TestUsersActivity extends AppCompatActivity {
public TextView mname,email,phone;
private RecyclerView recyclerView;
FirebaseAuth mAuth;
DatabaseReference mDatabase;
private FirebaseRecyclerAdapter adapter;
private LinearLayoutManager linearLayoutManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_users);
recyclerView = findViewById(R.id.listuser);
mDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
linearLayoutManager = new LinearLayoutManager(getApplicationContext());
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(linearLayoutManager);
fetch();
}
private void fetch() {
FirebaseRecyclerOptions<Users> options = new FirebaseRecyclerOptions.Builder<Users>()
.setQuery(mDatabase,Users.class)
.build();
adapter = new FirebaseRecyclerAdapter<Users, ViewHolder>(options) {
#Override
protected void onBindViewHolder(#NonNull ViewHolder myViewHolder, int i, #NonNull Users users) {
myViewHolder.setName(users.getFname() + " "+ users.getLname());
myViewHolder.setEmail(users.getEmail());
myViewHolder.setphone(users.getPhonenos());
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.user_list_row,parent, false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
#Override
public void onDataChanged() {
super.onDataChanged();
}
};
recyclerView.setAdapter(adapter);
adapter.startListening();
}
#Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(View itemView) {
super(itemView);
mname = itemView.findViewById(R.id.name);
email = itemView.findViewById(R.id.email);
phone = itemView.findViewById(R.id.phoneNos);
}
public void setName(String string) {
mname.setText(string);
}
public void setEmail(String string) {
email.setText(string);
}
public void setphone(String string){
phone.setText(string);
}
}
}
Below is my modelclass that i want to get just the name,email and phone nos from.
public class Users {
private String fname;
private String lname;
private String email;
private String phonenos;
private String jobTitle;
private String dateCreated;
private String lastlogin;
public Users(){
}
public Users(String fname, String lname, String email, String phonenos, String jobTitle, String dateCreated, String lastlogin) {
this.fname = fname;
this.lname = lname;
this.email = email;
this.phonenos = phonenos;
this.jobTitle = jobTitle;
this.dateCreated = dateCreated;
this.lastlogin = lastlogin;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhonenos() {
return phonenos;
}
public void setPhonenos(String phonenos) {
this.phonenos = phonenos;
}
public String getJobTitle() {
return jobTitle;
}
public void setJobTitle(String jobTitle) {
this.jobTitle = jobTitle;
}
public String getDateCreated() {
return dateCreated;
}
public void setDateCreated(String dateCreated) {
this.dateCreated = dateCreated;
}
public String getLastlogin() {
return lastlogin;
}
public void setLastlogin(String lastlogin) {
this.lastlogin = lastlogin;
}
}
I don't know if you must pass a query instead of a database reference
make the query a member variable
......
private Query query;
......
do this:
query = FirebaseDatabase.getInstance().getReference().child("Users");
and pass it like this to options
FirebaseRecyclerOptions<Users> options = new FirebaseRecyclerOptions.Builder<Users>()
.setQuery(query,Users.class)
.build();
ALSO MAKE SURE YOUR FIREBASE SECURITY RULES ARE NOT SET TO READ FALSE
I'm implementing my small app. Today,
I'm having trouble getting data from my Firebase.
Here is my Firebase structure:
This is modal Request:
public class Request {
// private String phone, name, address, total, status;
private String phone, name, address, status;
private int total;
private List<Order> foods;
public Request() {
}
public Request(String phone, String name, String address, int total, List<Order> foods) {
this.phone = phone;
this.name = name;
this.address = address;
this.total = total;
this.foods = foods;
this.status = "0"; //Default 0. 0: place, 1: shipping, 2: shipped
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public List<Order> getFoods() {
return foods;
}
public void setFoods(List<Order> foods) {
this.foods = foods;
}
}
I obtained the Order data by going to "PhoneNumber" and getting the
"ID Order" data as follows:
private FirebaseRecyclerAdapter<Request, OrderViewHolder> adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order_status);
//Firebase:
FirebaseDatabase database = FirebaseDatabase.getInstance();
requests = database.getReference("Requests");
//init:
recyclerView = (RecyclerView) findViewById(R.id.recycler_orderview);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
loadOrders(Common.currentUser.getPhone());
//Common.currentUser.getPhone() This is PhoneNumber current
}
private void loadOrders(final String phone) {
adapter = new FirebaseRecyclerAdapter<Request, OrderViewHolder>(
Request.class,
R.layout.order_item,
OrderViewHolder.class,
requests.child(phone) // I have access to "PhoneNumber"
) {
#Override
protected void populateViewHolder(OrderViewHolder viewHolder, Request model, int position) {
viewHolder.txtOrderId.setText(adapter.getRef(position).getKey());
viewHolder.txtOrderStatus.setText(convertCodeToStatus(model.getStatus()));
viewHolder.txtOrderPhone.setText(model.getPhone());
viewHolder.txtOrderAddress.setText(model.getAddress());
viewHolder.txtOrderTotal.setText(String.valueOf(model.getTotal()));
viewHolder.setItemClickListener(new ItemClickListener() {
#Override
public void onClick(View view, int position, boolean isLongClick) {
// Get CategoryID and send Activity Foods List:
Intent moveToOrderDetails = new Intent(OrderStatusActivity.this, OrderDetailsActivity.class);
moveToOrderDetails.putExtra("KeyOrder", adapter.getRef(position).getKey());
startActivity(moveToOrderDetails);
}
});
}
};
adapter.notifyDataSetChanged();
recyclerView.setAdapter(adapter);
}
And this is my Apdapter:
public class OrderViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnCreateContextMenuListener {
public TextView txtOrderId, txtOrderStatus, txtOrderPhone, txtOrderAddress, txtOrderTotal;
private ItemClickListener itemClickListener;
public OrderViewHolder(View itemView) {
super(itemView);
txtOrderId = (TextView) itemView.findViewById(R.id.order_id);
txtOrderStatus = (TextView) itemView.findViewById(R.id.order_status);
txtOrderPhone = (TextView) itemView.findViewById(R.id.order_phone);
txtOrderAddress = (TextView) itemView.findViewById(R.id.order_address);
txtOrderTotal = (TextView) itemView.findViewById(R.id.order_total);
itemView.setOnClickListener(this);
itemView.setOnCreateContextMenuListener(this);
}
public void setItemClickListener(ItemClickListener itemClickListener) {
this.itemClickListener = itemClickListener;
}
#Override
public void onClick(View view) {
itemClickListener.onClick(view,getAdapterPosition(),false);
}
#Override
public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
contextMenu.setHeaderTitle("Select the action");
contextMenu.add(0, 0, getAdapterPosition(), Common.UPDATE);
contextMenu.add(0, 1, getAdapterPosition(), Common.DELETE);
}
}
And now I'm having trouble figuring out how to get the data of all
orders without having to go to "Number Phone". I tried to think and
perform but failed.
This is image demo about an order: