How to manage activities in Android?

女生的网名这么多〃 提交于 2019-12-23 03:15:03

问题


I identified a problem in changing one activity using tab. In one tab activity I'm adding data to my SQLite database, and in the other tab activity I am displaying them using listview(array adapter). But when I come back to add data after adding new items to SQLite, the newly added records are not updated in my listview.

How do I fix this?


回答1:


You seem to be pulling the list data from a DB. Is there a reason why you are using an ArrayAdapter instead of a CursorAdapter?

Anyway, you should call notifyDataSetChanged() on your list adapter when the data has changed so it can refresh the view.




回答2:


you can add code to update your listview (via notifyDataSetChanged or some such) by overriding the onResume() method in your activity which is called whenever the activity is brought back to the foreground. See http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle



来源:https://stackoverflow.com/questions/3324467/how-to-manage-activities-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!