Custom Adapters
A custom adapter lets you bind objects to a layout that you control. Here we'll display a list of cricketers. To do this we'll need...
- A list of data.
- A layout to display the items.
- An adapter to bind the data to the layout.
- A ListActivity to display the list.
The end result looks like this.
The Layout
The layout is a standard axml layout. In this case we'll show an imageview and a couple of textviews.
The Adapter
The adapter is a class which inherits from BaseAdapter. It takes a list of Player objects and binds them to the layout as required. This is all the code for the class.
This is all pretty simple - the most interesting method is GetView which is where the data is bound to the layout. Android will try to reuse existing layouts which is why the layout is only inflated when the view is null. Because the views can be reused you need to make sure all the controls are handled each time the method is called, otherwise the 'old' data will still be displayed.
The Activity
The activity is basically the same as in the simple example. We create a list of data, an adapter (a PlayerAdapter this time), and assign it to the ListAdapter property.
thank a lot :)
ReplyDeleteCan you give me to see your class is Player.cs, thank
ReplyDeleteCasino - Bracket betting guide for your chance to win
ReplyDeleteThe Casino is a unique casino that has been around for over a casino-roll.com decade. It septcasino.com has managed to 토토 offer bsjeon great games such as Blackjack, Roulette and Video 메이저 토토 사이트 Poker,