There is no method 'getView' on a ListView class. And i expect i wouldn't 
return a number....

However, you do define a *static *field called *listItems*. Do you update 
the *listItems *field directly without notifying the your *BaseAdapter*? If 
so, this could be the problem. Notify the *BaseAdapter *by calling 
'notifyDataSetChanged()' on it after you make the appropriate changes to 
its data (*listItems*).

Note that you should not make this field (*listItems*) a *static*/class 
field. Just make it a regular/instance field, fill it with data and send 
this to your BaseAdapter and let your BaseAdapter handle it.

On Thursday, May 15, 2014 2:09:57 PM UTC-4, plnelson wrote:
>
>
> I'm getting a crash in my adapter's *getView()* routine because it's 
> being called with a position value of 6 and my datasource only has 6 items 
> in it. So I assumed that the position parameter should be in a range of 
> [0]-[5]? What determines the range of values in *getView(*)'s position 
> parameter?
>
> Details:
>
> the XML ...
>
> <ListView
>>   android:id="@android:id/list"
>>   android:layout_height="match_parent"
>>   android:layout_width="match_parent"
>>   android:cacheColorHint="@color/colGrey"
>>   android:background="@color/colGrey"
>>   android:clickable="true"
>>   android:fastScrollEnabled="true"
>>   android:choiceMode="none"/>
>>
>
> ...In MyListActivity, which is a ListActivity . . .
>
> public static ListView lv;   // my ListView in the code
>>
>
> ... during *onCreate()* . . .
>
>    setContentView(R.layout.mylist);
>    lv = getListView();
>
>
> create the adapter and bind it . . .
>
> mylistadapter = new MyListAdapter(MyListActivity.this);
>> setListAdapter(mylistadapter);   // bind the adapter
>>
>
> ...the data source is an ArrayList called listItems. during the course of 
> running the program its size varies and it may have been 15 earlier in 
> program execution . . .
>
> public static ArrayList<String>listItems=new ArrayList<String>();
>>
>
> ... in my adapter, which is a BaseAdapter, my ovveride of getCount() looks 
> like this . . .
>
> @Override
>> public int getCount() {
>>     return listItems.size();
>> }
>>
>
> ... when I call *getCount()* in *getView()* it returns 6, which is the 
> number of items in the data source, but if I call lv.*getView(*) it 
> returns 15. (any idea where this 15 is coming from?) Could that be why the 
> adapter is calling *getView()* with index too big?
>
> Thanks in advance!
>
>
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to