I've read some articles and watched video in order to understand how ListView
works. So, let's say I have list with 5 items (all items visible on screen). I have the following code in my custom adapter which inherited from BaseAdapter
:
@Override
public View getView(int position, View view, ViewGroup parent) {
System.out.println("item position: " + position + " view " + view);
if (view == null)
{
view = LayoutInflater.from(context).inflate(R.layout.list_view_item, null);
}
return view;
}
When I run this code I see the following output in console:
08-26 14:52:40.882: item position: 0 view null
08-26 14:52:40.883: item position: 1 view android.widget.RelativeLayout{ab5ffdd V.E...C.. ......I. 0,0-0,0 #7f0e00b8 app:id/item_container}
08-26 14:52:40.883: item position: 2 view android.widget.RelativeLayout{ab5ffdd V.E...C.. ......I. 0,0-0,0 #7f0e00b8 app:id/item_container}
08-26 14:52:40.884: item position: 3 view android.widget.RelativeLayout{ab5ffdd V.E...C.. ......I. 0,0-0,0 #7f0e00b8 app:id/item_container}
08-26 14:52:40.884: item position: 4 view android.widget.RelativeLayout{ab5ffdd V.E...C.. ......I. 0,0-0,0 #7f0e00b8 app:id/item_container}
08-26 14:52:40.884: item position: 0 view android.widget.RelativeLayout{ab5ffdd V.E...C.. ......I. 0,0-0,0 #7f0e00b8 app:id/item_container}
08-26 14:52:40.884: item position: 1 view android.widget.RelativeLayout{ab5ffdd V.E...C.. ......I. 0,0-0,0 #7f0e00b8 app:id/item_container}
08-26 14:52:40.884: item position: 2 view android.widget.RelativeLayout{ab5ffdd V.E...C.. ......I. 0,0-0,0 #7f0e00b8 app:id/item_container}
08-26 14:52:40.884: item position: 3 view android.widget.RelativeLayout{ab5ffdd V.E...C.. ......I. 0,0-0,0 #7f0e00b8 app:id/item_container}
08-26 14:52:40.884: item position: 4 view android.widget.RelativeLayout{ab5ffdd V.E...C.. ......I. 0,0-0,0 #7f0e00b8 app:id/item_container}
08-26 14:52:40.884: item position: 0 view android.widget.RelativeLayout{88bc756 V.E...C.. ......I. 0,0-1080,65 #7f0e00b8 app:id/item_container}
08-26 14:52:40.884: item position: 1 view android.widget.RelativeLayout{1264e60 V.E...C.. ......I. 0,68-1080,133 #7f0e00b8 app:id/item_container}
08-26 14:52:40.884: item position: 2 view android.widget.RelativeLayout{36b089 V.E...C.. ......I. 0,136-1080,201 #7f0e00b8 app:id/item_container}
08-26 14:52:40.884: item position: 3 view android.widget.RelativeLayout{e1a12bb V.E...C.. ......I. 0,204-1080,269 #7f0e00b8 app:id/item_container}
08-26 14:52:40.885: item position: 4 view android.widget.RelativeLayout{ab5ffdd V.E...C.. ......I. 0,0-0,0 #7f0e00b8 app:id/item_container}
I getView()
view
is null
only for the 0
position. After watching I supposed that I had null
for the first 5 calls (until all visible item views not initialized). Why only for the first? What I am missing?