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
Just use
myArrayList.remove(position);
inside a listener:I was not able to get notifyDataSetChanged() to work on updating my SimpleAdapter, so instead I tried first removing all views that were attached to the parent layout using removeAllViews(), then adding the ListView, and that worked, allowing me to update the UI:
If you want to maintain your scroll position when you refresh, and you can do this:
For the detail information, please see Android ListView: Maintain your scroll position when you refresh.
If you are going by android guide lines and you are using the
ContentProviders
to get data fromDatabase
and you are displaying it in theListView
using theCursorLoader
andCursorAdapters
,then you all changes to the related data will automatically be reflected in the ListView.Your
getContext().getContentResolver().notifyChange(uri, null);
on the cursor in theContentProvider
will be enough to reflect the changes .No need for the extra work around.But when you are not using these all then you need to tell the adapter when the dataset is changing. Also you need to re-populate / reload your dataset (say list) and then you need to call
notifyDataSetChanged()
on the adapter.notifyDataSetChanged()
wont work if there is no the changes in the datset. Here is the comment above the method in docs-Call runnable whenever you want:
OnCreate()
, you set your runnable thread:For me after changing information in sql database nothing could refresh list view( to be specific expandable list view) so if notifyDataSetChanged() doesn't help, you can try to clear your list first and add it again after that call notifyDataSetChanged(). For example
Hope it makes sense for you.