I am making a fragment where i am showing some data in recyclerview. But it is not showing anything not event the error. I am not using any @PropertyName of firebase Here is my firebase database snap
package com.example.lenovo.jdstudio;
import java.util.Map;
public class NewCustomer {
private String fName, lName, email, phone, photodesc, status;
private Map time;
public NewCustomer() {}
public NewCustomer(String fName, String lName, String email, String phone, String photodesc, String status, Map time) {
this.fName = fName;
this.lName = lName;
this.email = email;
this.phone = phone;
this.photodesc = photodesc;
this.status = status;
this.time = time;
}
public String getfName() {return fName;}
public String getlName() {return lName;}
public String getEmail() {return email;}
public String getPhone() {return phone;}
public String getPhotodesc() {return photodesc;}
public String getStatus() {return status;}
public Map getTime() {return time;}
}
public class UpdateOrder extends Fragment {
private View mView;
@BindView(R.id.customerDetailsRecyclerView)
RecyclerView mCustmoerDetails;
private FirebaseDatabase mDatabase;
private DatabaseReference mCustomerDatabase;
private FirebaseRecyclerAdapter firebaseRecyclerAdapter;
private LinearLayoutManager mManager;
private static final String TAG = UpdateOrder.class.getSimpleName();
public UpdateOrder() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
mView = inflater.inflate(R.layout.fragment_update_order, container, false);
ButterKnife.bind(this,mView);
mCustmoerDetails.setHasFixedSize(true);
mManager = new LinearLayoutManager(getActivity());
mCustmoerDetails.setLayoutManager(mManager);
Log.e(TAG,"Before firebaseoption");
mDatabase = FirebaseDatabase.getInstance();
mCustomerDatabase = mDatabase.getReference().child("new_customer");
FirebaseRecyclerOptions<NewCustomer> options =
new FirebaseRecyclerOptions.Builder<NewCustomer>().
setQuery(mCustomerDatabase,NewCustomer.class).
build();
// Log.e(TAG,"OnStart");
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<NewCustomer, CustDetailHolder> (options){
@Override
protected void onBindViewHolder(@NonNull CustDetailHolder holder, int position, @NonNull NewCustomer model) {
holder.setFname(model.getfName());
holder.setLname(model.getlName());
holder.setPhotoDetail(model.getPhotodesc());
}
@Override
public CustDetailHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.single_order_details, parent, false);
Log.e(TAG,"oncreate is called");
return new CustDetailHolder(view);
}
};
mCustmoerDetails.setAdapter(firebaseRecyclerAdapter);
return mView;
}
@Override
public void onStart() {
super.onStart();
firebaseRecyclerAdapter.startListening();
}
@Override
public void onStop() {
super.onStop();
firebaseRecyclerAdapter.stopListening();
}
//ViewHolder class
public static class CustDetailHolder extends RecyclerView.ViewHolder {
View mView;
public CustDetailHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setFname(String name) {
TextView FName = (TextView) mView.findViewById(R.id.cust_Fname);
FName.setText(name);
}
public void setLname(String name) {
TextView LName = (TextView) mView.findViewById(R.id.cust_Lname);
LName.setText(name);
}
public void setPhotoDetail(String photoDetail) {
TextView photo_details = (TextView) mView.findViewById(R.id.photo_Details);
photo_details.setText(photoDetail);
}
public void setOrderSpinner(String status){
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:id="@+id/cust_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="@dimen/dimen_15dp">
<TextView
android:id="@+id/cust_Fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fname"
android:textSize="16dp"
android:textStyle="bold" />
<TextView
android:id="@+id/cust_Lname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="3dp"
android:text="Lname"
android:textSize="16dp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="@+id/order_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/cust_name"
android:paddingLeft="@dimen/dimen_15dp"
android:paddingTop="@dimen/dimen_10dp"
android:text="order Status goes here"
android:textSize="15sp" />
<Spinner
android:id="@+id/order_status_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/cust_name"
android:layout_toRightOf="@id/order_status"
/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/order_status"
android:paddingLeft="15dp"
android:paddingTop="@dimen/dimen_10dp"
android:text="Photo Description:"
android:textSize="15sp" />
<TextView
android:id="@+id/photo_Details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/textView"
android:layout_below="@+id/textView"
android:paddingRight="@dimen/dimen_15dp"
android:paddingTop="@dimen/dimen_5dp"
android:text="4x6 id and passport"
android:textSize="12sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<RelativeLayout 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="com.example.lenovo.jdstudio.UpdateOrder">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/customerDetailsRecyclerView">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
Thanks For seeing the post. waiting for the answer. Please correct me if i am doing anything wrong. dont't mark it duplicate without reading it. I have attached all the listener.
As I see in your database, your fields do not corespond to those from your model class. To solve this, delete the old data, add fresh one and your problem will be solved.
As I see in your code, you are using for the declaration of your CustDetailHolder
class, the static
keyword, which is wrong. You only need:
public class CustDetailHolder extends RecyclerView.ViewHolder
Also remove ButterKnife.bind(this,mView);
as I see that you don't use it in your code.