How to add items to ListView in android : <p>Here i am trying to get the values from database and list them in ListView but after the 20 items i want to add some more items to the ListView when the user scrolls to the ListView end,But when the user scrolls to the end the ListView is erased completely and the new items are added. But i need the new items to be added at the end of previous List itself...</p>

<p>Here is my Android Code:</p>

<p>This will be executed at onCreate()</p>

<pre><code>  public void getLocalJobs() {
    empty.setVisibility(TextView.GONE);
    String url = ConfigCuboid.GET_JOBS_LOCAL;
    String url1 = Tags;
    String URL = url + url1;
    StringRequest stringRequest = new StringRequest(URL, new Response.Listener&lt;String&gt;() {
        @Override
        public void onResponse(String response) {
            showJSONLocal(response);
        }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            });
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
}

@TargetApi(Build.VERSION_CODES.M)
private void showJSONLocal(String response) {
    ParseJSONLocal pj = new ParseJSONLocal(response);
    pj.parseJSONLocal();

    CustomListLocal c1 = new CustomListLocal(this, ParseJSONLocal.job_local_id, ParseJSONLocal.user_names, ParseJSONOnline.job_typess, ParseJSONLocal.job_titles, ParseJSONLocal.job_works,
            ParseJSONLocal.job_dates, ParseJSONLocal.job_months, ParseJSONLocal.job_years,
            ParseJSONLocal.job_times, ParseJSONLocal.job_periods, ParseJSONLocal.job_areas, ParseJSONLocal.job_rates,
            ParseJSONLocal.user_ids, ParseJSONLocal.job_detailss, ParseJSONLocal.image, ParseJSONLocal.regtoken
            , ParseJSONLocal.verify);
    listViewWork.setAdapter(c1);
    Toast.makeText(getApplicationContext(),"ListNo=="+CustomListLocal.LastLocalJobId,Toast.LENGTH_SHORT).show();


    if (c1.isEmpty()) {
        empty.setVisibility(TextView.VISIBLE);
        pb.setVisibility(ProgressBar.GONE);
    }
    listViewWork.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView&lt;?&gt; parent, View view, int poss, long id) {
            Intent is = new Intent(getApplicationContext(), WorkProfileLocal.class);
            is.putExtra("Positions", poss);
            startActivity(is);
        }
    });


    listViewWork.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

        }

        @Override
        public void onScroll(AbsListView view,
                             int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            //Algorithm to check if the last item is visible or not
            final int lastItem = firstVisibleItem + visibleItemCount;
            if (lastItem == totalItemCount) {
                // you have reached end of list, load more data
               // Toast.makeText(getApplicationContext(),"ListIsOver",Toast.LENGTH_SHORT).show();
                Toast.makeText(getApplicationContext(),"ListNo=="+CustomListLocal.LastLocalJobId,Toast.LENGTH_SHORT).show();
                LoadLocalList();
            }

        }


    });
}
</code></pre>

<p>At the end of ListView this method is executed:</p>

<pre><code>   public void LoadLocalList(){

    empty.setVisibility(TextView.GONE);
    String url = ConfigCuboid.GET_LOADED_JOBS_LOCAL;
    String urll1="last_local_job_id=";
    String  urll11 = CustomListLocal.LastLocalJobId;
    String urll="&amp;job_title[]=";
    String url1 = Tags;

    String URL = url + urll1+urll11+urll+url1;
    StringRequest stringRequest = new StringRequest(URL, new Response.Listener&lt;String&gt;() {

        @Override
        public void onResponse(String response) {
            showJSONLocall(response);
        }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            });
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
}

@TargetApi(Build.VERSION_CODES.M)
private void showJSONLocall(String response) {
    ParseJSONLocal pj = new ParseJSONLocal(response);
    pj.parseJSONLocal();

    CustomListLocal c2 = new CustomListLocal(this, ParseJSONLocal.job_local_id, ParseJSONLocal.user_names, ParseJSONOnline.job_typess, ParseJSONLocal.job_titles, ParseJSONLocal.job_works,
            ParseJSONLocal.job_dates, ParseJSONLocal.job_months, ParseJSONLocal.job_years,
            ParseJSONLocal.job_times, ParseJSONLocal.job_periods, ParseJSONLocal.job_areas, ParseJSONLocal.job_rates,
            ParseJSONLocal.user_ids, ParseJSONLocal.job_detailss, ParseJSONLocal.image, ParseJSONLocal.regtoken
            , ParseJSONLocal.verify);
    listViewWork.setAdapter(c2);
    Toast.makeText(getApplicationContext(),"ListNo=="+CustomListLocal.LastLocalJobId,Toast.LENGTH_SHORT).show();


    if (c2.isEmpty()) {
        empty.setVisibility(TextView.VISIBLE);
        pb.setVisibility(ProgressBar.GONE);
    }
    listViewWork.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView&lt;?&gt; parent, View view, int poss, long id) {
            Intent is = new Intent(getApplicationContext(), WorkProfileLocal.class);
            is.putExtra("Positions", poss);
            startActivity(is);
        }
    });


}
</code></pre>
