Sometimes listView.getChildAt(int index) returns NULL (Android)
Because of view recycling, listView.getChildAt()
will only return a view for the positions it is displaying, and maybe one more. Maybe if you share more of your code we can help you figure out how to best tackle the problem.
Dmon and Azertiti are both correct... once your list is scrolled you find yourself in trouble. If the view isn't visible, then it doesn't exist (i.e. has been recycled by Android). You'll re-build the view once it's scrolled in.
Doing something like this should work:
View view;
int nFirstPos = lv_data.getFirstVisiblePosition();
int nWantedPos = invalidaEste - nFirstPos;
if ((nWantedPos >= 0) && (nWantedPos <= lv_data.getChildCount())
{
view = lv_data.getChildAt(nWantedPos);
if (view == null)
return;
// else we have the view we want
}
If that child is not visible on screen it means there is no View for it. I believe this is your not working case.
A good practice is to change the data behind your list adapter and call notifyDataSetChanged() on the adapter. This will inform the list the adapter has changed and paint again the views.
If you really want to manually update the view I guess the only solution is to retain the new values somewhere and wait until the View becomes visible. At that point you have a valid reference and can do the updates.