Update listview's viewitems without notifyDataSetChanged
I have an android application with a listview which .. blablabla .. presents a title and adress of a locati开发者_C百科on. Furthermore it displays a distance in meters and a compas.
http://i.stack.imgur.com/k5XHF.jpg (Sorry cant post screenshots yet :)
Whenever i get new compas data from my SensorManagers listener, i do notifyDataSetChanged the list is updated with the new bearing and everythings fine, however it seems to freeze the application for a few ms, nothing serious but the user can sure feel this laggy effect.
And now to my real question:
Is it possible to update only the "compasviews" without doing notifyDataSetChanged? I thought the best way to go about this would be some "findviewsbyid"function, save the destination in the compasview it self and only update the compasview, but i can only find the findViewById method.
Are you doing extensive calculations on the UI-thread? If so, consider implementing an AsyncTask
for calculating the new values and then call notifyDataSetChanged()
in onPostExecute()
-method of your AsyncTask
.
private class MyAsyncTask extends AsyncTask<Params, Progress, Result> {
@Override
protected Result doInBackground(Params... params) {
//Do calculations here
return null;
}
protected void onPostExecute(Result result) {
//Submit new data to the listadapter
adapater.notifyDataSetChanged();
};
}
精彩评论