json leader json leader - 5 months ago 90
Android Question

Use SetOnTabSelectdListerner of TabLayout on Xamarin Android?

Error: can not create instance of abstract class or interface

tablayout.SetOnTabSelectedListener(new TabLayout.IOnTabSelectedListener()
{


});

Answer

Try this:

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);    
    SetContentView(Resource.Layout.Main);

    var tabLayout = FindViewById<TabLayout>(Resource.Id.tab);

    tabLayout.TabSelected += (object sender, TabLayout.TabSelectedEventArgs e) =>
    {    
        var tab = e.Tab;
    };
}