How to refresh an Android ListView
after adding/deleting dynamic data?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Consider you have passed a list to your adapter.
Use:
list.getAdapter().notifyDataSetChanged()
to update your list.
I had an ArrayList which I wanted to display in a listview. ArrayList contained elements from mysql. I overrided onRefresh method and in that method I used tablelayout.removeAllViews(); and then repeated the process for getting data again from the database. But before that make sure to clear your ArrayList or whatever data structre or else new data will get appended to the old one..
The solutions proposed by people in this post works or not mainly depending on the Android version of your device. For Example to use the AddAll method you have to put android:minSdkVersion="10" in your android device.
To solve this questions for all devices I have created my on own method in my adapter and use inside the add and remove method inherits from ArrayAdapter that update you data without problems.
My Code: Using my own data class RaceResult, you use your own data model.
ResultGpRowAdapter.java
ResultsGp.java
After deleting data from list view, you have to call
refreshDrawableState()
. Here is the example:and
deleteContact
method inDatabaseHelper
class will be somewhat looks likeThe easiest is to just make a new Adaper and drop the old one:
i got some problems with dynamic refresh of my listview.
notifyDataSetChanged() did not work properly in my case[ I called the notifyDataSetChanged from another class]. Just in the case i edited the ListView in the running Activity (Thread). That video thanks to Christopher gave the final hint.
In my second class i used
to acces the update() from my Activity. This update includes
to tell the Adapter to refresh the view. Worked fine as far as I can say.