how to know when listview is finished loading data on android
You should not rely on the condition of "finish loading data", instead, you should set the image view visibility on the fly.
You should do something like this in your getView method of your list view adapter.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ItemView item;
if (convertView == null) {
item = mLayoutInflator.inflate(R.layout.listlayout)
} else {
item = (ItemView) convertView;
}
ImageView image = (ImageView)item.findViewById(R.id.yourimageidinitemview);
if(mTodoTask[posistion].isChecked) {
image.setVisibility(View.Visible);
} else {
image.setVisibility(View.Invisible);
}
return item;
}
It worked for me (mc.android.developer):
listview.getViewTreeObserver().addOnPreDrawListener(OnPreDrawListener);
private final ViewTreeObserver.OnPreDrawListener OnPreDrawListener = new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
//do changes
return true;
}
};
My solution:
list = (ListView) findViewById(R.id.list);
list.getViewTreeObserver().addOnPreDrawListener(mOnPreDrawListener);
...
private final ViewTreeObserver.OnPreDrawListener mOnPreDrawListener = new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
mMessageList.getViewTreeObserver().removeOnPreDrawListener(this);
// Do what you want to do on data loading here
return true;
}
};
Ok, i manage to solve the problem.
All i had to do, was override the getView method as said.
But, since Im using a SimpleCursorAdapter extended Class, I had to do something like this:
public View getView(int position, View convertView, ViewGroup parent){
View item = super.getView(position, convertView, parent);
//Validation code for drawing or not the check image
return item;
}
So, that did the work, and now everytime the listview is reordered or drawn or scrolled the views are refreshed correctly.
Thanks guys for the help