How to set ListActivity with RadListView?

2 posts, 0 answers
  1. Bill
    Bill avatar
    11 posts
    Member since:
    Nov 2017

    Posted 17 Nov Link to this post

    I'm following the example code from the ListView Getting Started section. At the end of the example, it states "set the list view as content of your page". How is this done? I tried SetContentView(listView) but get an error stating "cannot convert from RadListView to View". Here's my activity code:

     

    public class RouteDetailActivity : ListActivity
        {
            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);
     
                var listView = new RadListView
                {
                    ItemsSource = new ViewModel().Source,
                    ItemTemplate = new DataTemplate(() =>
                    {
                        var label = new Label {Margin = new Thickness(10)};
                        var content = new Grid();
                        content.Children.Add(label);
                        label.SetBinding(Label.TextProperty, new Binding(nameof(SourceItem.Name)));
     
                        return new ListViewTemplateCell
                        {
                            View = content
                        };
                    })
                };
     
                SetContentView(listView);
            }
        }
  2. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    488 posts

    Posted 20 Nov Link to this post

    Hello Bill,

    That code looks like it came from the Xamarin.Forms documentation. UI for Xamarin is primarily a Xamarin.Forms product, however we do have native versions of many of the controls that you can use on a non-Forms application. These native controls are the controls that eventually get rendered by the Xamarin.Forms PCL (via Custom Renderers)

    RadListView is one of those controls available using the native assemblies. We have the native Xamarin.iOS TKListView and the Xamarin.Android RadListView

    First, let me answer your question so that you can have some context, and then I'll show you where you can find the help to use the Android native RadListView

    Xamarin.Forms

    That code is intended for use in a Xamarin.Forms ContentPage, where you can add the UI for Xamarin Xamarin.Forms RadListView to the ContentPage by doing the following:

    <!-- XamarinForms XAML -->
    <ContentPage  ... >
     
        <Grid x:Name="RootGrid">
        </Grid>
    </ContentPage>


    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            // RadListView creation
            // ...
     
     
            // Set the ContentPage content with RadListView
            this.Content = listView;
        }
    }


    Xamarin.Android

    As I initially stated, it appears you want to use the native RadListView directly in a Xamarin.Android application. For this, you need to use the android control directly. You can follow the native control's documentation here to get started.

    You can find examples installed alongside UI for Xamarin, go here to learn where to find all the demos. In particular, you'll likely want these ones: C:\Program Files (x86)\Progress\Telerik UI for Xamarin R3 2017\Examples\Android


    If you have any further questions, you can open a support ticket here for direct support from the UI for Xamarin support team.

    Regards,
    Lance | Tech Support Engineer, Sr.
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top