The getView method in my custom ArrayAdapter is getting called multiple times, which I assume it is meant to. Problem is, I have a quantity TextView which is dynamically set
getView()
will be called multiple times as you note. it shouldn't matter, because your array adapter is based on the state of it's internal data model (array, list of objects, whatever). getView()
should be idempotent in that calling it multiple times shouldn't change the result.
you say "when you scroll and the box goes off screen the value disappears". note sure what mean. when you scroll one of the views generated in getView()
off the visible area, and when you scroll it back, the value is different? without any other information, i'd have to say that's not possible. the reason is again that unless you are modifying the internal state of the adapter, or changing the adapter, you will always generate the same view for a given position.
by the way, convertView
can be null, so you want to do something like,
View v = convertView;
if (v == null) {
v = inflater.inflate(...);
}
// now use v in the rest of the method
In your listview set android:height = "match_parent"
. Now getview
called your dataset count. we can reuse the convertview
. Check the convertview
if it is NULL
inflate your view. Otherwise, write your remaining code.
if(convertView ! = null)
{
//rest of your Code
}
else
{
//inflate that view
}