Using the new C1CollectionView at ComponentOne Studio for Xamarin

C1CollectionView

The CollectionView is a highly effective tool for organizing data, and also the new ComponentOne Studio for Xamarin ships using a brand new version of the popular control. The C1CollectionView provides a way of grouping, sorting, and filtering information, and the newest release brings this powerful ability to many new platforms. The two Xamarin.iOS and Xamarin.Android have their very own unique controls for interacting with a listing of data (the UITableView and RecyclerView respectively), and now we have added new CollectionView libraries which make it significantly easier to connect these controls directly to your information.

Why would I want to utilize a CollectionView?

A . NET style CollectionView let’s you greatly simplify some interactions with your information like filtering, sorting, and grouping. These functions aren’t commonly supported by data collections, along with a CollectionView wraps round your information to supply this functionality. Also (for iOS users) we are talking about another sort of control than that which you might think of should you consider a UICollectionView (which is a very different UI element for presenting information). Instead the CollectionView we’re describing has more in common with Microsoft’s managementwhich was initially a part of WPF. Our C1CollectionView is a non-UI component that provides support for the functions we have described above, in addition to additional support for cursor collections that allow you to incrementally load information. The newest release makes it easy to link your data to the native listing kinds of UITableViews and RecyclerViews.

Getting Started

Regardless of whether you are likely to be operating in Xamarin.iOS or even Xamarin.Android, the first step will be to bring the right NuGet packages for your project. NET projects potentially. It performs all of the work you’d associate with a . NET style CollectionView. After this you will add another library that acts as the connective tissues between the native lists types: either C1.iOS.CollectionView or C1.Android.CollectionView depending on platform.

Using the iOS C1CollectionView using a UITableView

Once you’ve got C1.iOS.CollectionView as part of your job, you will notice that this package contains a single (though significant) course: C1TableViewSource. This class acts as the bridge by the C1CollectionView to the UITableView, and simply by creating you own class that inherits from it you are able to override methods like GetItemCell to customize your UITableView. For instance:

public class MyCollectionViewSource : C1TableViewSource<MyDataItem>
{
private string CellIdentifier = “Default”;

public MyCollectionViewSource(UITableView tableView, ICollectionView<MyDataItem> collectionView, UIRefreshControl refreshControl = null)
: base(tableView, collectionView, refreshControl)
{
}

public override UITableViewCell GetItemCell(UITableView tableView, MyDataItem item)
{
UITableViewCell cell = tableView.DequeueReusableCell(CellIdentifier);
if (cell == null)
cell = new UITableViewCell(UITableViewCellStyle.Subtitle, CellIdentifier);

cell.TextLabel.Text = item.ItemName;
cell.DetailTextLabel.Text = item.ItemDateTime.ToLongTimeString();

return cell;
}
}

public class MyDataItem
{
public MyDataItem(int index)
{
this.ItemName = “My Data Item #” + index.ToString();
this.ItemDateTime = DateTime.Now;
}
public string ItemName { get; set; }
public DateTime ItemDateTime { get; set; }

}

There are more samples available on GitHub that additional exemplify further uses including utilizing the sorting, grouping, filtering, and on-demand loading to fantastic effect with live data from YouTube.

Using the Android C1CollectionView with a RecyclerView

After you’ve added the C1.Android.CollectionView package you will gain access to single class: C1RecyclerViewAdapter. This course bridges the C1CollectionView to the RecyclerView that’s a part of Android.Support.V7.Widge.RecyclerView. Once more you can inherit from this class to link to the native control, and create your own ViewHolder to customize the appearance of the respective cells. For example:

internal class MyAdapter : C1RecyclerViewAdapter<MyDataItem>
{

public MyAdapter(ICollectionView<MyDataItem> collectionView)
: base(collectionView)
{
}

protected override RecyclerView.ViewHolder OnCreateItemViewHolder(ViewGroup parent)
{
var view = LayoutInflater.From(parent.Context)
.Inflate(Resource.Layout.ListItem, null, false);
return new MyViewHolder(view);
}

protected override void OnBindItemViewHolder(RecyclerView.ViewHolder holder, int position)
{
var h = holder as MyViewHolder;
var item = CollectionView[position];
h.SetTitle(item.ItemName);
h.SetSubtitle(item.ItemDateTime.ToLongTimeString());
}
}
internal class MyViewHolder : RecyclerView.ViewHolder
{
private TextView _title;
private TextView _subTitle;

public MyViewHolder(View itemView)
: base(itemView)
{
_title = itemView.FindViewById<TextView>(Resource.Id.Title);
_subTitle = itemView.FindViewById<TextView>(Resource.Id.Subtitle);
var icon = itemView.FindViewById<ImageView>(Resource.Id.Icon);
icon.Visibility = ViewStates.Gone;
}

internal void SetTitle(string title)
{
_title.Text = title;
}

internal void SetSubtitle(string subTitle)
{
_subTitle.Text = subTitle;
}
}
public class MyDataItem
{
public MyDataItem(int index)
{
this.ItemName = “My Data Item #” + index.ToString();
this.ItemDateTime = DateTime.Now;
}
public string ItemName { get; set; }
public DateTime ItemDateTime { get; set; }

}

Source : Hire Xamarin Developer |  xamarin development company

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>