开发者

Using BaseAdapter to populate GridView

I am having some difficulty in getting my implementation of a BaseAdapter working to populate a GridView. I've a few questions around the workings of the BaseAdapter, based on the example here: http://developer.android.com/resources/tutorials/views/hello-gridview.html

In my implementation, my BaseAdapter.getCount() method returns 130. Therefore I would have expected the getView() method to be invoked once for each count. However, as far as I can see getView() is only invoked appr开发者_StackOverflow中文版oximately 70 times....why is this?

If getView() is used to construct the View object at each position in the grid, then what is the purpose of getItem() which returns an Object?

Lastly, I wish my grid to be 10 columns wide and 13 rows in height. To achieve this, do I just set the android:numColumns attribute to be 10?

Any help is appreciated in understanding this.

Thanks.


  • However, as far as I can see getView() is only invoked approximately 70 times....why is this?

    It generates the views as they are rendered to the screen

  • If getView() is used to construct the View object at each position in the grid, then what is the purpose of getItem() which returns an Object?

getItem(int position)
Get the data item associated with the specified position in the data set.

As the description says, it returns the underlying data associated with that position as opposed to the View for the same position.

  • To achieve this, do I just set the android:numColumns attribute to be 10?

android:numColumns setNumColumns(int) Defines how many columns to show.

The description is quite explicit here.
BTW, this last question is one that you could easily test yourself rather than asking here...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜