Hello. My question is the following: There is a SimpleAdapter in which messages from the server are loaded. In the adapter, the method ( Parcelable state = sList.onSaveInstanceState(); и sList.onRestoreInstanceState(state); ) I save the current position of the scroll, as the adapter updates the data every 5 seconds. Those. My adapter is constantly being recreated, but I do not need this. I want to do this ... Json'om every 5 seconds to check for the presence of a new message, and if it is, then pull out this message and add it to an existing adapter. As I understand it, you need to create a separate class AsyncTask, which will send requests every 5 seconds. Did, pulled the data (written in the logs) ... but how to add them to an existing adapter now?

I update the handler data, in the FriendMsgLoad () method, AsynkTask itself is sending a request via HttpURLConnection.

 class RefreshActivity extends Thread { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { mHandler.postDelayed(this, 5000); FriendMsgLoad friendMsgLoad = new FriendMsgLoad(); friendMsgLoad.execute(); } }); } } 
  • You can add the data to the list ( List<> ) that you use for the adapter and call the adapter notifyDataSetChanged() . At the same time you do not need to recreate the adapter - Vladyslav Matviienko
  • Essentially, I do so, in data = new ArrayList<Map<String, Object>>(); I add the data, I drive it to the map, but as soon as I call notifyDataSetChanged , the error NullPointerException is received - sergei1094
  • So you are doing something wrong. The error indicates on which line it occurs, and because of what. See the error of the error, or at least show it. - Vladyslav Matviienko 1:01 pm
  • I use 2 classes. In the first I have the adapter itself and in the second a network request. String[] from = {LV_MSGID, LV_MSG, LV_USID_MSG, LV_MSG_TIME}; int[] to = {R.id.id_msg, R.id.msg, R.id.id_msg_user, R.id.msg_time}; new FriendMsgActivity().dataChanged(data, from, to); After a network request, I pass the data to the dataChanged method and try to assign values ​​to the adapter already inside the FriendMsgActivity class. java.lang.IllegalStateException: System services not available to Activities before onCreate() I get an error java.lang.IllegalStateException: System services not available to Activities before onCreate() - sergei1094
  • Do not leave me please :) - sergei1094

0