Why doesn't the code work?

I am able to download data from the server. It remains to learn how to make them load in portions depending on the screen scrolling. The server is JSONArray. I read it in parts, but something is not very successful (

Here is what he wrote:

public class Main extends ListActivity { // откуда начинать считывать данные private int from = 0; // количество считываемых данных private int number = 10; private ListView listView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); listView = (ListView)findViewById(android.R.id.list); ItemAdapter adapter = new ItemAdapter(); setTitle("List of search engines"); // Считываем первую порцию данных MyTask mt = new MyTask(); Log.d("AsynsTask - MyTask", "create MyTask: " + mt.hashCode()); mt.execute(); listView.setOnScrollListener(new OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) {} @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (view.getAdapter() != null && ((firstVisibleItem + visibleItemCount) >= totalItemCount)){ from = totalItemCount; MyTask mt = new MyTask(); mt.execute(); adapter.notifyDataSetChanged(); } } }); } class MyTask extends AsyncTask<String, Integer, Void> { @Override protected Void doInBackground(String... params) { // Здесь происходит считывание данных json и парсинг rsj = new ReadStringJson("http://ed.sadko.mobi/askdroid.web/api?action=engines_list_by_alphabet&from=" + from + "&number=" + number); try { parsingFunction(rsj.readFromServer()); } catch (IOException ex) { Log.e("IOException: ", ex.toString()); } catch (JSONException ex) { Log.e("JSONException: ", ex.toString()); } return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); listView.setAdapter(adapter); } } 

And here are the logs

11-04 11:13:20.302: I/Choreographer(819): Skipped 69 frames! The application may be doing too much work on its main thread. 11-04 11:13:21.882: W/ImageLoader(819): Unable to create external cache directory 11-04 11:13:22.132: W/ImageLoader(819): Unable to create external cache directory 11-04 11:13:22.372: D/dalvikvm(819): GC_CONCURRENT freed 232K, 4% free 8182K/8519K, paused 152ms+88ms, total 333ms 11-04 11:13:22.402: W/ImageLoader(819): Unable to create external cache directory 11-04 11:13:22.612: W/ImageLoader(819): Unable to create external cache directory 11-04 11:13:22.712: W/ImageLoader(819): Unable to create external cache directory 11-04 11:13:22.792: W/ImageLoader(819): Unable to create external cache directory ...

Somehow it turns out that after scrolling new data is not loaded (

  • And what kind of error is that? Show Log at least - rasmisha
  • IMHO better on the server to write a function that will give the data "page by page", request the page number, and get it exactly ... - Vladyslav Matviienko
  • Well, there is no way to implement this business on the server side ... What can I do here? - Stas0n
  • Try adding to the manifest: <uses-permission android: name = "android.permission.WRITE_EXTERNAL_STORAGE" /> - ReinRaus

0