How to add more item in a list view without refreshing the previous item

I have a listview in which i am adding some data after fixed interval.but I don't want to set the adapter again as it will refresh the complete list.Is there any method to add item without refreshing the complete list.

Thanks in advance.

Answers


You probably want to use the following (in RecycleView not ListView):

notifyItemInserted(0);//NOT notifyDataChanged()
recyclerViewSource.scrollToPosition(0);
//Scroll up, to use this you'll need an instance of the adapter's RecycleView 

You can call adapter.notifyDataSetChanged() to just update the list.

Adapter's getView() is called at different times and there is no particular pattern. So your views are updated whenever ListView wants it to be updated.

But as far as I see it, you are looking for adapter.notifyDataSetChanged. The workflow should be something like this.

Set adapter to ListView
Add data to adapter`
Call notifyDataSetChanged() on adapter.

It will at least prevent your list to bounce back to first item on the list. Hope that helps.


you can use this .notifyDataSetChanged()

However notifyDataSetChanged() only works For an ArrayAdapter,if you use the add, insert, remove, and clear functions on the Adapter.


You can use

adapter.add(<new data item>); // to add data to your adapter
adapter.notifyDatasetChanged();  // to refresh

For eg.

ArrayAdapter<String> adapter;

public void onCreate() {
   ....
   ....

   ArryList<String> data = new ArrayList<String>();
   for(int i=0; i<10; i++) {
     data.add("Item " + (i+1));
   }

   adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data);
   setListAdapter(adapter);
}

Now whenever you have new data to be added to list you can do following

private void appendToList(ArrayList<String> newData) {
    for(String data : newData)
        adapter.add(data);

    adapter.notifyDatasetChanged();
}

Need Your Help

C# How do I set the volume of sound bytes[]

c# audio ffmpeg

Im trying to change the volume of sound bytes[] in C#. Im reading a sound file with FFMPEG and and wanna change the volume on the fly. I found some examples and but I didnt understand them.

How to implement the background change viewpoint when the user is moving the iOS device?

ios core-motion motion

As you may know that the iOS 7 home screen can do a visual things like, when the user moving the device, the background is moving as well. How can I do the similar thing in my application? Let say ...