Remove All Ads from XDA

How do I implement a onscroll Listener to my listview?

3 posts
Thanks Meter: 0
By xemkruz2012, Junior Member on 24th August 2014, 10:02 PM
Post Reply Email Thread
I have a large data to load from JSON.

I have implemented a custom list view by following a tutorial, now since the data is huge I want it load as the user scrolls.

This is my LoadRestaurant class code which is inside the main activity.

class LoadRestaurants extends AsyncTask<String, String, String> {

        //Show Progress Dialog
        protected void onPreExecute() {
            pDialog = new ProgressDialog(SearchAll.this);
            pDialog.setMessage("Loading All Restaurants...");

        protected String doInBackground(String... arg) {
            //building parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();

            //Getting JSON from URL
            String json = jsonParser.makeHttpRequest(URL_RESTAURANT_LIST, "GET", params);

            //Log Cat Response Check
            Log.d("Areas JSON: ", "> " + json);

            try {
                restaurants = new JSONArray(json);

                if (restaurants != null) {
                    //loop through all restaurants
                    for (int i = 0; i < restaurants.length(); i++) {
                        JSONObject c = restaurants.getJSONObject(i);

                        //Storing each json  object in the variable.
                        String id = c.getString(TAG_ID);
                        String name = c.getString(TAG_NAME);
                        String location = c.getString(TAG_LOCATION);
                        String rating = c.getString(TAG_RATING);

                        //Creating New Hashmap
                        HashMap<String, String>  map = new HashMap<String, String>();

                        //adding each child node to Hashmap key
                        map.put(TAG_ID, id);
                        map.put(TAG_NAME, name);
                        map.put(TAG_LOCATION, location);
                        map.put(TAG_RATING, rating);

                        //adding HashList to ArrayList

            } catch (JSONException e) {

            return null;

        protected void onPostExecute(String file_url) {

            //dismiss the dialog

            //Updating UI from the Background Thread
            runOnUiThread(new Runnable() {
                public void run() {

                    ListAdapter adapter = new SimpleAdapter(
                            SearchAll.this, restaurant_list,
                            R.layout.listview_restaurants, new String[]{
                            TAG_ID, TAG_NAME, TAG_LOCATION, TAG_RATING}, new int[]{

                    ListView lv = getListView();

                    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                          //  Bundle bundle = new Bundle();
                             Intent intent = new Intent(SearchAll.this, RestaurantProfile.class);
                                String loginId = ((TextView) view.findViewById(;

                                intent.putExtra("login_id", loginId);




I want to load around 20 restaurants and then it auto loads another 20 as soon as user reaches the end of first 20.

There are lots of tutorials online but its confusing to implement.

Please help me out!
25th August 2014, 09:58 AM |#2  
Junior Member
Thanks Meter: 6
The custom ListView, support for automatic loading you can try
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes