recyclerview No adapter attached; skipping layout

后端 未结 30 3142
走了就别回头了
走了就别回头了 2020-11-21 04:51

Just implemented RecyclerView in my code, replacing ListView.

Everything works fine. The data is displayed.

But error messages are

30条回答
  •  情话喂你
    2020-11-21 05:30

    I had the same problem and realized I was setting both the LayoutManager and adapter after retrieving the data from my source instead of setting the two in the onCreate method.

    salesAdapter = new SalesAdapter(this,ordersList);
            salesView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
            salesView.setAdapter(salesAdapter);
    

    Then notified the adapter on data change

                   //get the Orders
                    Orders orders;
                    JSONArray ordersArray = jObj.getJSONArray("orders");
                        for (int i = 0; i < ordersArray.length() ; i++) {
                            JSONObject orderItem = ordersArray.getJSONObject(i);
                            //populate the Order model
    
                            orders = new Orders(
                                    orderItem.getString("order_id"),
                                    orderItem.getString("customer"),
                                    orderItem.getString("date_added"),
                                    orderItem.getString("total"));
                            ordersList.add(i,orders);
                            salesAdapter.notifyDataSetChanged();
                        }
    

提交回复
热议问题