Alex
Alex

Reputation: 11

FirebaseRecyclerAdapter doesn't populate firebase.ui 3.1.2

FirebaseRecyclerAdapter - is just showing a blank screen, I get no errors when compiling and no errors while scrolling around. I've added Adapter().startListening(); to the onStart, I've added data to firebase in the orders child. I'd be greatful for any help.

Here is my FirebaseRecyclerAdapter,

private FirebaseRecyclerAdapter<Orders, OrderViewHolder> Adapter()
{
    Query query = mDatabaseReference.limitToLast(50);
    final FirebaseRecyclerOptions<Orders> options =
            new FirebaseRecyclerOptions.Builder<Orders>()
                    .setQuery(query, Orders.class)
                    .build();

    return new FirebaseRecyclerAdapter<Orders, OrderViewHolder>(options) {

        @Override
        public OrderViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.order_single_layout, parent, false);
            return new OrderViewHolder(view);
        }

        @Override
        protected void onBindViewHolder(OrderViewHolder ViewHolder, int position, Orders orders) {
            ViewHolder.setOrderID(orders.getOrder_id());
            ViewHolder.setProductName(orders.getProduct_name());
            ViewHolder.setStatus(orders.getStatus());  
        }           
    };
}

My Viewholder

public static class OrderViewHolder extends RecyclerView.ViewHolder
{
    View mView;
    private OrderViewHolder(View itemView)
    {
        super(itemView);
        mView = itemView;
    }
    public void setOrderID(String orderID)
    {
        TextView orderIdTextView = (TextView) mView.findViewById(R.id.orderSingle_OrderIDTextView);
        orderIdTextView.setText(orderID);
    }
    public void setStatus(String status)
    {
        TextView statusTextView = (TextView) mView.findViewById(R.id.orderSingle_StatusTextView);
        statusTextView.setText(status);
    }
    public void setProductName(String productName)
    {
        TextView productNameTextView = (TextView) mView.findViewById(R.id.orderSingle_ProductNameTextView);
        productNameTextView.setText(productName);
    }
}

on Create

  @Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_orders);

    mDatabaseReference = FirebaseDatabase.getInstance().getReference().child("orders");
    adapter = Adapter();
    mOrderList = (RecyclerView) findViewById(R.id.order_RecyclerView);
    mLayoutManager = new LinearLayoutManager(this);
    mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mOrderList.setHasFixedSize(true);
    mOrderList.setLayoutManager(mLayoutManager);
    mOrderList.setAdapter(adapter);

}

activityOrder.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.chat.OrdersActivity">

<android.support.v7.widget.RecyclerView
    android:id="@+id/order_RecyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"
    android:layout_alignParentEnd="true">
</android.support.v7.widget.RecyclerView>

The messageView for each message intended to go into the RecyclerView

RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:id="@+id/orderSingle_ProductNameTextView"
    style="@style/textView_style"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="15dp"
    android:textColor="#000000"
    android:text="Product"
    android:textSize="18sp" />

<TextView
    android:id="@+id/orderSingle_StatusTextView"
    style="@style/textView_style"
    android:text="Status"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignStart="@+id/orderSingle_ProductNameTextView"
    android:layout_below="@+id/orderSingle_ProductNameTextView"
    android:layout_marginTop="12dp"
    android:textColor="#000000"/>

<TextView
    android:id="@+id/orderSingle_OrderIDTextView"
    style="@style/textView_style"
    android:text="order_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignStart="@+id/orderSingle_ProductNameTextView"
    android:layout_below="@+id/orderSingle_StatusTextView"
    android:layout_marginTop="12dp"
    android:textColor="#000000" />

Upvotes: 0

Views: 165

Answers (1)

Alex
Alex

Reputation: 11

Got it to start working by adding .setLifecycleOwner(this) to

   final FirebaseRecyclerOptions<Orders> options =
        new FirebaseRecyclerOptions.Builder<Orders>()
                .setQuery(query, Orders.class)
                .build();

No idea why it works now but it does

Upvotes: 1

Related Questions