android - ListView load more from JSON -


I'm trying to create a listView which loads more items in the previous listView item is appearing I have code to get data from JSON which is working fine.

This is my MyFragment.java

  public category MyFragment fragment extension {JSONObject jsonobject; JSONObject newjsonobject; JSONArray jsonarray; JSONArray newjsonarray; List view list view; ListViewAdapter adapter; Array list & lieutenant; Hashmap & lt; String, string & gt; & Gt; array list; Array list & lieutenant; Hashmap & lt; String, string & gt; & Gt; Newarraylist; Public fixed string NAME = "name"; Private int petlest; @ Override Public View Crate View (LayoutInfleter Inflator, View Group Container, Bundle Saved InstantState) {View Routview = Inflator.In Flat (R.Lailout.list View, Container, Incorrect); New downloadjson () carry about (); Return root view; } Private class downloadsJoson Sink Task & lt; Zero, zero, zero> {@Override Safe Volume Doine Background (Zero ... Parameter) {arraylist = New Arreelist & Lt; Hashmap & lt; String, string & gt; & Gt; (); Jsonobject = JSONfunctions.getJSONfromURL ("http://192.168.0.103/contacts.json"); Try {jsonarray = jsonobject.getJSONArray ("contact"); (Int i = 0; i & lt; jsonarray.length (); i ++) {Hashmap  String, string & gt; Map = new hashmap & lt; String, string & gt; (); Jsonobject = jsonarray.getJSONObject (i); Map.put ("name", jsonobject.getString ("name")); Arraylist.add (map); }} Hold (JSOXECTION E) {log. A ("error", E. mailsage ()); E.printStackTrace (); } Return tap; } @Override Secure Zero PostExecute (ZERO ARGS) {listview = (list view) getActivity () FindViewById (R.id.listview); Adapter = new ListViewAdapter (getActivity (), array list); Listview.setOnScrollListener (New AbsListView.OnScrollListener) ({View AbsListView, integer first visible item, int viewoutimount, int total ITemCount) {last integer lastItem = first visititimate + visible itemCount; NewAvatar List = New Array List & Lt; Hashmap & lt; String, string & gt; & Gt; ; (); If (lastItem == totalItemCount) {if (preLast = lastItem!) {PreLast = lastItem; Newjsonobject = JSONfunctions.getJSONfromURL ("http://192.168.0.103/contacts2.json"); Try {newjsonarray = newjsonobject .getJSONArray ("contact"); For (int i = 0; I & lt; newjsonarray.length (); i ++) {HashMap & LT; String, string & gt; Newmap = n Eve hashmapped  

This works fine if I try this type of

  newmap.put ("name", "name"); Newarraylist.add (newmap); Arraylist.addAll (newarraylist); Adapter.notifyDataSetChanged ();  

But when I try to get data from JSON, when I scroll to the last item, the job stops. What is I doing wrong?

Contacts2.json

  {"contact": [{"name" : "Name"}, {"name": "name2"}]}  


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -