Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,808,657 Members 43,264 Now Online
XDA Developers Android and Mobile Development Forum

How do I implement a onscroll Listener to my listview?

Tip us?
Junior Member - OP
Thanks Meter 0
Posts: 3
Join Date: Mar 2014
Unhappy How do I implement a onscroll Listener to my listview?

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!
Junior Member
Thanks Meter 6
Posts: 12
Join Date: Aug 2014
The custom ListView, support for automatic loading you can try
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes