0

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

enter image description here

NewCustomer.java (my module class)

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;}
}

Updaterder.java

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){

        }
    }


}

single_order_detail.xml

<?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>

fragment_update_order.xml

<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.

Aakash
  • 101
  • 2
  • 11
  • Possible duplicate of [Firebase @PropertyName doesn't work](https://stackoverflow.com/questions/38681260/firebase-propertyname-doesnt-work) – Cătălin Florescu Feb 20 '18 at 12:30
  • Also check this, another reason why adapter might not show anything: https://stackoverflow.com/questions/47228262/firebaselistadapter-not-pushing-individual-items-for-chat-app-firebase-ui-3-1 – Peter Haddad Feb 22 '18 at 19:49

4 Answers4

4

I have faced the same problem as you described, thank you for sharing the problem and comments. I followed them and found out that I should remove setHasFixedSize(true) from the recycler view. Also, I should override the onStart and onStop methods with start and stop listening for the adapter, respectively. That has solved my problem of not showing anything on recycler view.

P.S: I am aware that you have found your answer and solved your problem long ago. I am just sharing this conclusion here as it was not directly extractable from the discussion.

YHN
  • 75
  • 5
2

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.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Ty for viewing i did the change as you said but it still not working .please see my question again – Aakash Feb 20 '18 at 12:20
  • `ButterKnife.bind(this.mView);` is for the `@BindView` – Aakash Feb 20 '18 at 12:38
  • Have you tried to remove the static keyword? Does it work? – Alex Mamo Feb 20 '18 at 12:39
  • yes i have did that change and run the code but it still not working can you see that duplicate mark and tell me acc. what should i do – Aakash Feb 20 '18 at 12:45
  • What duplicate mark? Do you have an error? Or the `RecyclerView` remains empty? – Alex Mamo Feb 20 '18 at 12:47
  • No .some one has said that my question is same as this question [link](https://stackoverflow.com/questions/38681260/firebase-propertyname-doesnt-work) – Aakash Feb 20 '18 at 12:50
  • We'll see later what is moderator opinion. In the mean while,Do you have an error? Or the RecyclerView remains empty? – Alex Mamo Feb 20 '18 at 12:52
  • it remains empty. What i am seeing that it is not even printing the `Log.e(TAG,"On create is called")` from the `onCreateViewHolder()` it means that **adapter is having some problem .** But I don't know what is the problem. – Aakash Feb 20 '18 at 12:56
  • does it because of Map? – Aakash Feb 20 '18 at 13:15
  • One more question. Are you sure you don't have old records anymore? If you have, delete them and try again. So? – Alex Mamo Feb 20 '18 at 13:16
  • yes i have deleted the whole node and i inserted the new data from my add user fragment then also – Aakash Feb 20 '18 at 13:18
  • I see in your error: `E/UpdateOrder: Fname null`. So there is somewhere left `Fname`. Find it, delete it and try again. So? – Alex Mamo Feb 20 '18 at 13:23
  • I have added a value event listener and try to deserialized the data by datasnaphot.getValue() and after that i printed this statement `Log.e(TAG,"fname"+cust.getFname)` thats why it is showing like that – Aakash Feb 20 '18 at 13:30
  • I understand. Try to see my answer from [here](https://stackoverflow.com/questions/48846631/i-cant-see-any-firebaserecycleradapter-items-on-my-layout/48851402#48851402). – Alex Mamo Feb 20 '18 at 13:34
  • I had removed Map time variable and change the corresponding field now it is showing the data but only once i.e if i start it at first time it is showing the data but after first time if i re run the app it again giving the blank screen – Aakash Feb 20 '18 at 14:17
  • Do you have an error when you start the second time? – Alex Mamo Feb 20 '18 at 14:32
  • Can you show me your entire code? Add a screenshot in your comment. – Alex Mamo Feb 20 '18 at 14:38
  • it worked hell yeah TY for all the support and bearing with me [ Source ](https://github.com/firebase/FirebaseUI-Android/issues/204) removed the `setHasFixedSize(true)` – Aakash Feb 20 '18 at 14:40
  • You're welcome! Good to hear that it worked! If you think that my answer helped you, please consider accepting it. Thanks! – Alex Mamo Feb 20 '18 at 14:41
  • also you think my question can help some one else upvote it. Most welcome – Aakash Feb 20 '18 at 14:47
0

The strings in your model class:

fName
lName

must be the same as in your database, in your database you have this:

FName
LName

For Anyone Checking this:

It was solved as I said in my comment:

@Aakash keep it, but put this instead mCustmoerDetails.setHasFixedSize(false) – Peter Haddad yesterday

OP had to add mCustmoerDetails.setHasFixedSize(false) instead of mCustmoerDetails.setHasFixedSize(true)

or remove mCustmoerDetails.setHasFixedSize(true)

Community
  • 1
  • 1
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • @Aakash please try my answer – Peter Haddad Feb 20 '18 at 13:02
  • my model class is having the same name please look again – Aakash Feb 20 '18 at 13:04
  • kk i am trying your answer – Aakash Feb 20 '18 at 13:05
  • I have added a value event listener and then i print the log it is showing me null value as follows `D/NativeCrypto: ssl=0x62995160 sslRead buf=0x423a8da0 len=1,timeo=0 W/ClassMapper: No setter/field for -L5n7VYRTA-2vgojwfhg found on class com.example.lenovo.jdstudio.NewCustomer E/UpdateOrder: snapshot DataSnapshot { key = new_customer, value = {-L5n7VYRTA-2vgojwfhg={time=1519128808600, photodesc=I'd passport, phone=9028847184, lName=vidlan, status=placed, email=aakashbidln@gmsil.com, fName=aakash}} } E/UpdateOrder: Fname null` – Aakash Feb 20 '18 at 13:10
  • You need to change the Fname to fName @Aakash – Peter Haddad Feb 20 '18 at 13:13
  • i have changed that only please see the image of database again – Aakash Feb 20 '18 at 13:16
  • `E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.lenovo.jdstudio, PID: 22231 com.google.firebase.database.DatabaseException: Class java.util.Map has generic type parameters, please use GenericTypeIndicator instead ` it is giving this error – Aakash Feb 20 '18 at 13:43
  • @Aakash keep it, but put this instead `mCustmoerDetails.setHasFixedSize(false)` – Peter Haddad Feb 20 '18 at 13:45
  • still giving the same error i think it is bcoz `Map time` variable – Aakash Feb 20 '18 at 13:50
  • @Aakash why did u choose his answer as correct and i told u to remove `sethasfixedsize(true)` in the previous comments – Peter Haddad Feb 20 '18 at 17:18
  • 1
    Sorry i don't mean to hurt you thanks to you also for helping me a lot and step given by him has also helped me you both help me unfortunately due to my low reputation i can't upvote your ans.. sorry bro – Aakash Feb 20 '18 at 18:26
  • It is fine, not a problem – Peter Haddad Feb 20 '18 at 18:36
0

Man maybe your forgot to call firebaseRecyclerAdapter.startListening in your @override onStart(){}