Im trying to write a single activity app, extending ListActivity. I have a class that generates data to String arrays. Wha开发者_StackOverflow中文版t i want is to refresh the activity's view periodically, so it would represent actual values. I've made my own adapter extending BaseAdapter. It contains 2 TextViews in a single row to inflate with those String arrays. When i set my new adapter in onCreate with setListAdapter(myAdapter) it works well. I just cant figure out, how can i refresh periodically the view to represent the actual values of the arrays used in myAdapter after the first inflation. I was trying calling notifyDataSetChanged() in an other thread periodically with the help of Thread.sleep(), but that doesnt work, because you cant call notifyDataSetChanged() from another thread. Im a a beginner and new to adapters, have read tons of examples but i just cant figure it out.
Create a new Handler() for your activity in onCreate(), and post a Runnable to it that calls notifyDataSetChanged(). You can reschedule the Runnable on intervals however you like.
精彩评论