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 8044913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:23:02+00:00 2026-06-05T05:23:02+00:00

I have a list view, when I go back and come back to my

  • 0

I have a list view, when I go back and come back to my list activity the list is duplicated. The first list needs to be removed so only one list is displayed. Any ideas???

This is my List Activity code:

package com.sportspubfinder;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class ListPubsActivity extends Activity {

    ProgressDialog ShowProgress;

    ListView lv1;

    int selectedRadius;

    Double userLat;
    Double userLong;


    public static ArrayList<SetterGetter> PubList = new ArrayList<SetterGetter>();

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

        lv1 = (ListView) findViewById(R.id.listView1);

        Bundle extras = getIntent().getExtras();
        if(extras != null){
            //retrieve the passed through radius and location readings 
            selectedRadius = extras.getInt("radius_set");
            userLat = extras.getDouble("latitude_set");
            userLong = extras.getDouble("longitude_set");
        }

         //show progres bar whilst a connection is made with the url
        ShowProgress = ProgressDialog.show(ListPubsActivity.this, "",
                "Loading Pubs. Please wait...", true);

        /* --If the INAPUB api was implemented, the url would take the passed radius (selectRadius) and location of the user---
          * "http://api.inapub.co.uk/venues/geocode/"+userLat+"/"+userLong+"/"+selectedRadius+"/?API_Key=7xa3tdmjkhu6jwjvp746zgg4");*/ 
        new loadingTask().execute("http://itsuite.it.brighton.ac.uk/jp232/pubs.php");

        //check which list item has been selected
        lv1.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {

                Intent intent = new Intent(ListPubsActivity.this, PubActivity.class);
                //pass the pubs information through to the next activity
                intent.putExtra("pubName", PubList.get(position).getName()); 
                intent.putExtra("pubImage", PubList.get(position).getThumbnail()); 
                intent.putExtra("pubAddress", PubList.get(position).getAddress()); 
                intent.putExtra("pubTown", PubList.get(position).getTown()); 
                intent.putExtra("pubCounty", PubList.get(position).getCounty()); 
                intent.putExtra("pubDescription", PubList.get(position).getDescription()); 
                intent.putExtra("pubFacilities", PubList.get(position).getFacilities()); 
                intent.putExtra("pubRating", PubList.get(position).getRating()); 
                intent.putExtra("pubLatitude", PubList.get(position).getLatitude()); 
                intent.putExtra("pubLongitude", PubList.get(position).getLongitude());

                startActivity(intent);

            }
        });

    }

    class loadingTask extends AsyncTask<String, Void, String> {
        //check if there's an Internet connection
        /*public boolean isOnline() {
            ConnectivityManager cm =
                (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

            return cm.getActiveNetworkInfo() != null && 
               cm.getActiveNetworkInfo().isConnectedOrConnecting();
        }*/

        protected String doInBackground(String... urls) {
            //in background wait to receive the information from the ListHandler
            SAXHelper sh = null;
            try {
                sh = new SAXHelper(urls[0]);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            sh.parseContent("");
            return "";

        }

        protected void onPostExecute(String s) {
            //add Custom List Adapter once ListHandler has been received 
            lv1.setAdapter(new CustomAdapter(ListPubsActivity.this, PubList));
            //stop progress bar
            ShowProgress.dismiss();
        }
    }

    class SAXHelper {

        public HashMap<String, String> userList = new HashMap<String, String>();
        private URL url2;

        public SAXHelper(String url1) throws MalformedURLException {
            this.url2 = new URL(url1);
        }

        public ListHandler parseContent(String parseContent) {
            //add the ListHandler
            ListHandler df = new ListHandler();
            try {

                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = spf.newSAXParser();
                XMLReader xr = sp.getXMLReader();
                xr.setContentHandler(df);
                xr.parse(new InputSource(url2.openStream()));
            } catch (Exception e) {
                e.printStackTrace();
            }
            return df;
        }

    }

    @Override
    protected void onPause(){
       super.onPause();
    }

    @Override
    protected void onStop(){
       super.onStop();
    }

}
  • 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-05T05:23:05+00:00Added an answer on June 5, 2026 at 5:23 am
    public static ArrayList PubList = new ArrayList();
    

    I believe, due to the static type, your list contents are getting appended.

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

Sidebar

Related Questions

In my view this is one of the strangest problem i have ever come
I have a list of items in one view controller. I can select an
I have list view and its adapter stored as global variables. I am not
In my application, I have list view. Selecting another item in it, triggers an
I have a list view filled with data. I set up a context menu
I have a list view with over 100 items. Each of these items show
I have a list view contains 100+ rows. every time the user opens the
I have chat list view in which sender name should be left aligned and
I have a list view, editText and button. editText and button are my footer
I have a list view as following: <ListView x:Name=lvLedger Height={Binding Path=GridHight, ElementName=ledgerList} Width={Binding Path=GridWidth,

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.