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

  • SEARCH
  • Home
  • 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 8913671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:31:18+00:00 2026-06-15T04:31:18+00:00

I have a ListView with a SimpleAdapter. The Data for the ListView comes from

  • 0

I have a ListView with a SimpleAdapter. The Data for the ListView comes from json. I want to update the ListView every 5 min.
That works fine… But the ListView is allway a double. All items are to times in the ListView. Why? And wenn I update then 3 times….
I try

setListAdapter(null);

and

mylist.clear();

no effect

public class StartActivity extends ListActivity {
    TextView text_1,text_2 ;
    private Timer autoUpdate;
    ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
    Button btnShowLocation;

    // GPSTracker class
    GpsData gps;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listplaceholder);

        btnShowLocation = (Button) findViewById(R.id.report_btn);

        // show location button click event
        btnShowLocation.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Intent intent = new Intent(StartActivity.this, ReportActivity.class);
                startActivity(intent);

            }
        });

        new task().execute();
    }

     @Override
     public void onResume() {
      super.onResume();
      autoUpdate = new Timer();
      autoUpdate.schedule(new TimerTask() {
       @Override
       public void run() {
        runOnUiThread(new Runnable() {
         public void run() {
             new task().execute();
         }
        });
       }
      }, 0, 300000); // updates each 5 min
     }

class task extends AsyncTask<String, String, Void>
{
private ProgressDialog progressDialog = new ProgressDialog(StartActivity.this);
    InputStream is = null ;
    String result = "";
    protected void onPreExecute() {
       progressDialog.setMessage("Status Update...");
       progressDialog.show();
       progressDialog.setOnCancelListener(new OnCancelListener() {
    @Override
        public void onCancel(DialogInterface arg0) {
        task.this.cancel(true);
       }
    });
     }
       @Override
    protected Void doInBackground(String... params) {
           //mylist.clear();


           JSONObject json = jsonFunctions.getJSONfromURL("http://my.de", mlat, mlon);

      try{
        //String text = getString(R.string.report_TJ);
        JSONArray  earthquakes = json.getJSONArray("uTraf");

            for(int i=0;i<earthquakes.length();i++){                        
                HashMap<String, String> map = new HashMap<String, String>();    
                JSONObject e = earthquakes.getJSONObject(i);

                map.put("id",  String.valueOf(i));
                map.put("first", "Stau: " + e.getString("road") + ", " + e.getString("county"));
                map.put("second", e.getString("timestamp") + ", " + e.getString("suburb"));
                mylist.add(map);            
            }       
      }catch(JSONException e)        {
         Log.e("log_tag", "Error parsing data "+e.toString());
      }

            return null;

        }
    protected void onPostExecute(Void v) {
        //setListAdapter(null);
        ListAdapter adapter = new SimpleAdapter(StartActivity.this, mylist , R.layout.main, 
                new String[] { "first", "second" }, 
                new int[] { R.id.item_title, R.id.item_subtitle });

setListAdapter(adapter);

final ListView lv = getListView();
lv.setTextFilterEnabled(true);  
lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              
        @SuppressWarnings("unchecked")
        HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);                   
        Toast.makeText(StartActivity.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_SHORT).show(); 

    }
});
            this.progressDialog.dismiss();

        } 
    }


@Override
public void onPause() {
 autoUpdate.cancel();
 super.onPause();
}


}
  • 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-15T04:31:20+00:00Added an answer on June 15, 2026 at 4:31 am

    Your problem is with the call mylist.add(map); inside your for loop in doInBackground.

    Your creating a map is fine but by calling the add function on mylist you are appending it to the list and not overriding the current map with the same keys. If you want to update existing items in the listview as opposed to just overwriting with fresh data then the mylist variable should probably be a HashMap also.

    EDIT – Solution:

    In doInBackground, just before you enter the loop to process data

    (for(int i=0;i<earthquakes.length();i++))
    

    call mylist.clear(). This will empty your array list before you start to add new data to it.

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

Sidebar

Related Questions

i have my listview activity that works pretty fine but i have an annoying
I have dynamic listview on my android client app that receive data from remote
I have a SimpleAdapter that populates a ListView, but when the user presses an
I have ListView that uses a GridView to display several columns of data. Two
I have a listview with custom rows and that extends SimpleAdapter. Each row consist
I'm trying to get data from a SimpleAdapter, but I don't know the syntax
I have an app which reads some data from JSON, and I have 2
I have a ListView populated by a SimpleAdapter, which gets values from an ArrayList
I have one listview in which i am displaying data that i got, it
Currently, I have json data of several twitter feeds that I parse to fill

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.