I have a custom list adapter:
class ResultsListAdapter extends ArrayAdapter {
in the overridden \'getView\' method I do a
Ques: Why Adapter calls getView() manytimes? Ans: As Listview renders on scrolling is refreshes it's view with next upcoming views, for which adapter needs to get views by calling getView().
Ques: Why it's calls lesser if listview width and height set to fill_parent? Ans: Because as inflator has the fixed size for the screen area for list it calculates once for rendering the views onto the screen.
Hope it will resolve your query.
For all of you who still (After setting the height
of the ListView
to match_parent
) are stuck (like I was):
You also have to set the height
of the parent layout to match_parent
.
See example below. The LinearLayout
is the parent here:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/something" />
<ListView
android:id="@+id/friendsList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
I was having the same problem with the dropdown in an AutoCompleteTextView. I was fighting with the problem for two days until I arrive here and you show me the solution.
If I write dropDownHeight="match_parent" the problem is fixed. Now the problem is related to UI (when you have one item the dropdown is too large) but the problem of multiple calls (much more important) is fixed.
Thank you!!
Try with match_parent
on the layout_height
property of the list view. It will prevent getView()
to be called so often.
This maybe coming late but if you are using layout_weight
remember to always set layout_width="0dp"
"Why is getview called for each row three times?" Because getView is called when you scroll on listview and to say better then that it is called when the position of an view of your list is changed!