Articles in this section
Category / Section

How to use Xamarin.Forms ListView in Xamarin.Android and Xamarin.iOS platforms?

1 min read

You can convert the SfListView from Xamarin Forms into Xamarin Android and Xamarin iOS.

For Android you need to convert the main page in to fragment and replace it in the OnCreate method of MainActivity.cs file

C#

 
public class MainActivity : Activity
{
    public static MainActivity Instance;
 
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
 
        Forms.Init(this, bundle);
        Instance = this;
 
        SetContentView(Resource.Layout.Main);
           
        var mainPage = new SfListViewPage().CreateFragment(this);
        FragmentManager
        .BeginTransaction()
        .Replace(Resource.Id.fragment_frame_layout, mainPage)
        .Commit();
    }
}

 

For iOS you need to create the instance for the window and set the main page as rootview in the FinishedLaunching method of AppDelegate.cs file.

 

 
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
    Forms.Init();
 
    Instance = this;
    // create a new window instance based on the screen size
    Window = new UIWindow(UIScreen.MainScreen.Bounds);
    SfListViewRenderer.Init();
    var mainPage = new SfListViewPage().CreateViewController();
 
    // If you have defined a root view controller, set it here:
        Window.RootViewController = mainPage;
 
    // make the window visible
    Window.MakeKeyAndVisible();
 
    return true;
}

 

Click here to download the sample.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied