Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8279137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:14:08+00:00 2026-06-08T09:14:08+00:00

I have created a listview using LazyAdapter. When i scroll to the bottom of

  • 0

I have created a listview using LazyAdapter.

When i scroll to the bottom of the list the new data show up but it clears all the old data.

How i can append the new data below old data?

This is my main activity code

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.NodeList;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.sax.Element;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

public class AndroidJSONParsingActivity extends Activity {

    // url to make request


    // JSON Node names
    static final String TAG_CONTACTS = "comics";
    static final String TAG_ID = "id";
    static final String TAG_NAME = "title";
    static final String TAG_EMAIL = "id";
    static final String TAG_PHONE_MOBILE = "image";

    // contacts JSONArray
    JSONArray contacts = null;
    ListView list;
    LazyAdapter adapter;
    static int counter = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

                        // call the function
                LoadData();




    }

    public void LoadData(){
        String url = "http://myurl.com/?start=" + counter;
        // Hashmap for ListView
                ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();

                // Creating JSON Parser instance
                JSONParser jParser = new JSONParser();

                // getting JSON string from URL
                JSONObject json = jParser.getJSONFromUrl(url);

                try {
                    // Getting Array of Contacts
                    contacts = json.getJSONArray(TAG_CONTACTS);

                    // looping through All Contacts
                    for(int i = 0; i < contacts.length(); i++){
                        JSONObject c = contacts.getJSONObject(i);

                        // Storing each json item in variable
                        String id = c.getString(TAG_ID);
                        String name = c.getString(TAG_NAME);
                        String email = c.getString(TAG_EMAIL);
                        String mobile = c.getString(TAG_PHONE_MOBILE);
                        // Phone number is agin JSON Object

                        // creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();

                        // adding each child node to HashMap key => value
                        map.put(TAG_ID, id);
                        map.put(TAG_NAME, name);
                        map.put(TAG_EMAIL, email);
                        map.put(TAG_PHONE_MOBILE, mobile);

                        // adding HashList to ArrayList
                        contactList.add(map);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }


                /**
                 * Updating parsed JSON data into ListView
                 * */
        list=(ListView)findViewById(R.id.list);

                // Getting adapter by passing xml data ArrayList
                adapter=new LazyAdapter(this, contactList);        
                list.setAdapter(adapter);

                // Launching new screen on Selecting Single ListItem
                list.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                            int position, long id) {
                        // getting values from selected ListItem
                        String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
                        String cost = ((TextView) view.findViewById(R.id.email)).getText().toString();
                        String description = ((TextView) view.findViewById(R.id.mobile)).getText().toString();

                        // Starting new intent
                        Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
                        in.putExtra(TAG_NAME, name);
                        in.putExtra(TAG_EMAIL, cost);
                        in.putExtra(TAG_PHONE_MOBILE, description);
                        startActivity(in);

                    }
                });


                list.setOnScrollListener(new OnScrollListener() {



                    @Override
                    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                        if (view.getAdapter() != null && ((firstVisibleItem + visibleItemCount) >= totalItemCount)) {
                            //Log.v(TAG, "onListEnd, extending list");
                            //mPrevTotalItemCount = totalItemCount;
                            counter = totalItemCount;

                            LoadData();
                            adapter.notifyDataSetChanged();}
                    }

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

                });





    }
}

And this is my LazyAdapter.java file

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class LazyAdapter extends BaseAdapter {

    private Activity activity;
    private ArrayList<HashMap<String, String>> data;

    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 



    public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }


    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.list_row, null);

        TextView title = (TextView)vi.findViewById(R.id.title); // title
        TextView artist = (TextView)vi.findViewById(R.id.artist); // artist name
        TextView duration = (TextView)vi.findViewById(R.id.duration); // duration
        ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image

        HashMap<String, String> song = new HashMap<String, String>();
        song = data.get(position);



        // Setting all values in listview
        title.setText(song.get(AndroidJSONParsingActivity.TAG_NAME));
        artist.setText(song.get(AndroidJSONParsingActivity.TAG_ID));
        duration.setText(song.get(AndroidJSONParsingActivity.TAG_EMAIL));
        imageLoader.DisplayImage(song.get(AndroidJSONParsingActivity.TAG_PHONE_MOBILE), thumb_image);
        return vi;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:14:09+00:00Added an answer on June 8, 2026 at 9:14 am

    I think the problem is in your problem is that in the loadData() method. Each time you recreate the contactList..

    ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();

    and then you call…

    adapter=new LazyAdapter(this, contactList);        
    list.setAdapter(adapter);
    

    This creates a new adapter every time you load data, instead of appending data to your current adapter. You already have the adapter as an instance variable, so you do not need to initialize it every time. You should be initializing your listview and your adapter in the onCreate() method, then you never have to do it again. Then, simply add the new contact list into the existing adapter, and call notifyDataSetChanged(); and you should be good to go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom listview using adapter. Each row of the list view
We have created custom listview by using the Base adapter. List view contains Text
I have created a custom titlebar for all my listview activities using the following
i have created a listview to show all the contents of a database on
I have created a listview using following tutorial link http://www.ezzylearning.com/tutorial.aspx?tid=1763429 Outcome of this is,
HI Guyz i have created a sectioned custom listview using baseadapter its working fine
I have created a listview using the default ArrayAdapter. However, to select an item
basicly, I'm trying to show the result of a listview (created with QSLite)but in
I have a ListView to show some images (using ImageList ). Everything works fine
I have a ListView than contains a list of image created from web link

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.