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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:20:34+00:00 2026-06-09T16:20:34+00:00

ListView doesn’t seem to refresh when notifyDataSetChanged(); is called, but does refresh when its

  • 0

ListView doesn’t seem to refresh when notifyDataSetChanged(); is called, but does refresh when its adapter gets set again.

In my Activity onCreate I initialize my ListView and my adapter. Then I have this Hanler that checks for new values every second. listview.setAdapter(arrayAdapter); works but arrayAdapter.notifyDataSetChanged(); doesn’t do anything.

Here is the code:

    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

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

            arrayAdapter = new ArrayAdapter<Integer>(this,android.R.layout. simple_list_item_1, myIntegers);
            lv.setAdapter(arrayAdapter);
    }

    private Handler handler = new Handler() {

            @Override
            public void handleMessage(Message msg) {
                if (msg.what == DIS){
                    handler.sendEmptyMessageDelayed(DIS, 1000);
                    if(!refresh()){
                        handler.removeMessages(DIS);
                    }
                }
            }
        };

   public boolean refresh(){

        if(ports.isEmpty()){
            return false;
        }else{
            listview.setAdapter(arrayAdapter); //WORKS
    arrayAdapter.notifyDataSetChanged(); // DOESN'T WORK
            return true;
            }
    }

So I was wondering how to make that work with notifyDataSetChanged, because I read that it is the right way to do it, and anyway even if the setAdapter does work it makes my listview jump to beginning every time it refreshes it.

EDIT:

To clarify things, I am adding more values to myIntegers.

  • 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-09T16:20:35+00:00Added an answer on June 9, 2026 at 4:20 pm

    Try instead adding the values using the adapter.add() method. I dont think you can modify the array that was used to create the adapter and then expect it to hold an updated instance to update the views from. Best of Luck!

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

Sidebar

Related Questions

The ListView shows nothing when I want to set the adapter to display the
I have below code in my Form Load event handler but the ListView doesn't
How can I get the visible items from a winforms listview? There doesn't seem
ListView.ColumnClick doesn't seem to fire for clicks in the header area that is outside
Whenever I add something to the SQLiteDatabase , the ListView doesn't show it, but
i have problem with listview... i'm trying to add OnClickListener but in still doesn't
I'm trying to select the first item in a ListView programmatically, but it doesn't
I have the following listview, but it doesn't show the actual records, but only
I want to make a listview of files in folder,but it doesn't work. What's
In my application listView('refresh') doesn't work. Here is my code I create listView dynamically

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.