Skip to content Skip to sidebar Skip to footer

Android Update Recyclerview Items

i have simple problem on update recyclerview items by new data, i'm wondering which code work fine without using data binding, in my code adding new items trigger by click on butto

Solution 1:

Because the model is a reference to the recycler view adapter itself, any changes made to the outside model object links back to adapter.So outside your adapter class where model is located just, call notifyDataSetChange there.so adapter.setData(model); remove and simply do adapter.notifyDatasetChange();

 @Override
    public void clickOnSendCommandToRobot() {
        RobotViewModel temp = new RobotViewModel();
        temp.setMessage(Math.round(Math.random()) + "");
        temp.setMessageType(SV.RobotMessageType.SENT_BY_ROBOT.ordinal());
        model.add(temp);

        Log.e(TAG, model.size() + "");

        adapter.notifyDataSetChanged();        }

Post a Comment for "Android Update Recyclerview Items"