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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:31:43+00:00 2026-06-06T02:31:43+00:00

I am trying to update my Activity’s ListView from within the onLocationChanged function of

  • 0

I am trying to update my Activity’s ListView from within the onLocationChanged function of a Location Listener using notifyDatasetChanged() but it doesnt work. I can however use setListAdapter from the same point in my code and this will work.

Here is my code:

public class TestListeners extends ListActivity {

    ArrayAdapter adapter;

    private final LocationListener networkLocationListener = new LocationListener() {

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            switch (status) {
            case LocationProvider.AVAILABLE:
                break;
            case LocationProvider.OUT_OF_SERVICE:
                break;
            case LocationProvider.TEMPORARILY_UNAVAILABLE:
                break;
            }
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onLocationChanged(Location location) {
            checkProximity(location.getLatitude(), location.getLongitude(), cx);
        }
    };

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //get a list here venueNamesArray        
        //etc

         adapter = new ArrayAdapter<String>(this,
         android.R.layout.simple_list_item_1, android.R.id.text1,
         venueNamesArray); 

         setListAdapter(adapter);
    }


    private void checkProximity(double curLat, double curLon, Context cx) {

        //get a different list here venueNamesArray
        //etc

        adapter = new ArrayAdapter<String>(getApplicationContext(),
                android.R.layout.simple_list_item_1, android.R.id.text1,
                venueNamesArray);

        adapter.notifyDataSetChanged();//this doesnt work and no error is thrown
            setListAdapter(adapter);//this works


    }

}

The reason I want to use notifyDatasetChanged() instead of setListAdapter is because the listview scrolls back to the top upon setting it. No error is throw when I use notifyDatasetChanged() so it is hard for me to see why this isnt working.

I have tried using a normal ListView for this instead of extending ListActivity and ran into the same problem.

  • 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-06T02:31:46+00:00Added an answer on June 6, 2026 at 2:31 am

    because you are creating a new adapter every time. you are not only changing the data in same adapter that is currently linked to list ……..

    As you are creating the new adapter and new adter will not linked with list untill you call setAdpter So it is not worth to call adapter.notifyDataSetChanged(); for adtper that is not linked with the list…

    Solution

    There is no need to create the adapter each time . jsut create and set in once in On-create and only change the ArrayList (add/remove not create new) and call adapter.notifyDataSetChanged();

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

Sidebar

Related Questions

i'm trying to update a listbox using ajax/jquery/webmethod. from inspecting network activity in developer
I'm trying to make a widget to my app, but it doesnt update. I
I am trying to communicate/update UI from Service to activity. The broadcast I receive
Hai am trying to get the gps location using BroadCast Receiver.its working fine,But i
I trying to update a model on a callback but the validation is causing
When trying to update a subversion working copy from Netbeans, I get the following
I am trying to update a field in a table with data from another
So I'm trying to update an object in my MS SQL 2005 database using
I am trying to update my status using SSO and with an onClickListener on
I am trying to refactor my package using Eclipse org.sheehan.activity to org.sheehan.stocks.activity For some

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.