No More Adapters and No More UITableDataSource

rzee7rzee7 INUniversity ✭✭✭✭✭


I'm a programmer and developing application for iOS and Android while working on both platform I have found a very common problem Actually Not Problem. :) a necessary thing that every mobile developer have to implement during data binding whether it is an iOS or android.

Those important implementation is BaseAdapter in android, UITableDataSource in iOS. these implementation have to be there if you are using ListView, GridView,Spinner, TableView, PickerView controls, each controls should have their separate binding source :(

When we need same functionality for each control, why not one implementation Don't you want save your time? time to another pain :)

I have a good news for all Xamarin Developers We have a component that help us to do the same thing it self for us. :) Yeppeeeeeeeee! Let's have a look below.

Android :

  • ListView
  • GridView

    using PRAAdapterLess;
    public class ListViewActivity : Activity, IDataRowView<Movie>
        protected override void OnCreate(Bundle bundle)
            //Register this activity
            var listView = FindViewById<ListView>(Resource.Id.list);
            listView.Adapter = new PRAAdapter<Movie>(this, DataProvider.GetMovies());
        public View GetDataRowView(int position, View convertView, ViewGroup parent, Movie item)
            View view = convertView;
            if (view == null)
                view = LayoutInflater.Inflate(Resource.Layout.ListItem, parent, false);
            view.FindViewById<TextView>(Resource.Id.title).Text = item.Title;
            view.FindViewById<TextView>(Resource.Id.rating).Text = item.Rating.ToString();
            view.FindViewById<TextView>(Resource.Id.genre).Text = item.Genere;
            view.FindViewById<TextView>(Resource.Id.releaseYear).Text = item.Year.ToString();
            return view;

iOS :

  • TableView

    using PRATableSourceLess;
    public partial class PRATableViewController : UIViewController, IDataCellView<Movie>
        public PRATableViewController()
            : base("PRATableViewController", null)
        public override void DidReceiveMemoryWarning()
            // Releases the view if it doesn't have a superview.
        public override void ViewDidLoad()
            base.ViewDidLoad ();
            PRAService.Register<IDataCellView<Movie>> (this);
            var tableView = new UITableView (new RectangleF (0f, 20f, 320f, 480f));
            tableView.Source = new PRATableSource<Movie> (DataProvider.GetMovies(), 70);
            Add (tableView);
        public UITableViewCell GetDataRowView(UITableView tableView, NSIndexPath indexPath, Movie item)
            //Sorry about the code : Just for demo :)
            var cell = TableCellView.Create ();
            cell.BindData (item);
            return cell;
        public void RowSelected(UITableView tableView, NSIndexPath indexPath)
            //Do something on table row click :)

Cheers :)

I hope it will save your time and help you in your development :)



Sign In or Register to comment.