I make a simple chat. Faced a problem: when sending a new message there is no data change in the Recycler View, which acts as a list of messages. This list is updated as soon as I start scrolling it or hiding the keyboard. Googled a bit, tried a couple of ways to fix it. Nothing present in the code below corrected my problem: (Actually, the code itself: (json comes to this method with a new message and I add it to the list)
@Override public void onFrame(WebSocket websocket, WebSocketFrame frame) throws Exception { Log.i("fg", "onFrame"); JSONObject data = new JSONObject(frame.getPayloadText()); if(data.has("data")) { MyMessage myMessage = new MyMessage(data.getString("user_id"), data.getString("data"), data.getString("login"), data.getString("unix_time"), data.getString("user_id"), data.getString("avatar")); adapter.addToStart(myMessage, true); adapter.update(myMessage); } adapter.notifyDataSetChanged(); adapter.notifyItemInserted(adapter.getItemCount()); } Thank you for your help!
notifyDataSetChangedworks only with collections passed to the adapter's constructor. - Flippyadapter.addToStart(myMessage, true);You have addeditemto the top of the list, and to the adapter you say that at the end, it may be necessary:adapter.notifyItemInserted(0);- woesssaddToStartandupdateadapter methods. - eugeneek