android - How to get item height of ListView without using OnItemClickListener? -
i use piece of code vertically center selected item of listview;
@override public void onitemclick(adapterview<?> adapter, view v, int position, long id) { m_listview.smoothscrolltopositionfromtop(position, (m_listview.getheight() - v.getheight()) / 2, 100); }
there no problem this. problem can't center default selected item because can't neither listview height nor item height.
what tried;
- creating views
inflater
(returns 0 height) - running
performclick()
method on default selected item (does nothing, throws no exception)
so can do?
note: item heights equal.
take code:
// int totalheight = 0;//it listview height (int = 0, len = listadapter.getcount(); < len; i++) { view listitem = listadapter.getview(i, null, listview); listitem.measure(0, 0); int list_child_item_height = listitem.getmeasuredheight()+listview.getdividerheight();//item height totalheight += list_child_item_height; // }
Comments
Post a Comment