On Fri, Aug 19, 2011 at 8:41 PM, Goutom <[email protected]> wrote:
> I want to get all child of a listview.
Why?
> int count = listview.getAdapter().getCount();
This is not the number of children of the ListView. getChildCount() on
ListView is the number of children of the ListView.
> for (int i = 0; i < count; ++i) {
> View row = (View) listview.getChildAt(i); // this line return "null" when
> the view is not in focus is listview.
> CheckBox check = (CheckBox) row.findViewById(R.id.AppCheckBox);
> if (check.isChecked()) {
> // some code
> } else
> // some code
> }
> I have 10 row in listview, 8 in focus.
No, you have 8 rows in your ListView. Your adapter might have 10
items, but you only have 8 rows in the ListView.
> After looping 8 times it gives null for View row.
Of course. That's what you wrote.
If you didn't want it to crash, do not compare apples (number of items
in the adapter) to oranges (number of children of the ListView).
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy
_The Busy Coder's Guide to Android Development_ Version 3.6 Available!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en