Exception of inflate Custom View with custom state

I want to define a custom view with custom state. The code are as follows.

attrs.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
      <declare-styleable name="TabPage">
        <attr name="tab_state_selected" format="boolean"/>
      </declare-styleable>
    </resources>

TabPage.cs:

namespace Sfi.Fw.Ui.Tab
{
    public class TabPage : TextView
    {
        public TabPage(Context context) : this(context, null)
        {

        }

        public TabPage(Context context, IAttributeSet attrs) : this(context, attrs, 0)
        {

        }

        public TabPage(Context context, IAttributeSet attrs, int defStyle)
            : base(context, attrs, defStyle)
        {
            TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.TabPage, defStyle, 0);
            bool str = a.GetBoolean(Resource.Styleable.TabPage_tab_state_selected, false);
            a.Recycle();
        }
    }
}

Main.axml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res/Sfi.Fw"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
      <sfi.fw.TabPage
          custom:tab_state_selected="true"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Test Tab Item"
          />
</LinearLayout>

MainActivity.cs:

public class MainActivity : Activity
{

    protected override void OnCreate (Bundle bundle)
    {
    base.OnCreate (bundle);

        SetContentView (Resource.Layout.Main);
    }
}

when I start debug, vs give me the exception below

    0x21 in System.Diagnostics.Debugger.Mono_UnhandledException_internal    C#
    0x1 in System.Diagnostics.Debugger.Mono_UnhandledException  C#
    0x26 in object.3acf87a3-0149-4883-a54d-a49e8592ae4b C#
    0x85 in Android.Runtime.JNIEnv.CallNonvirtualVoidMethod at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.10.2-branch/4b53fbd0/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:895 C#
    0x99 in Android.App.Activity.SetContentView at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.10.2-branch/4b53fbd0/source/monodroid/src/Mono.Android/platforms/android-14/src/generated/Android.App.Activity.cs:3830 C#
>   0xF in Sfi.Fw.MainActivity.OnCreate at c:\Users\Public\Documents\Workspace\BE\SVN\Projects\SFI.FW.Android\SFI.FW.Android\MainActivity.cs:58 C#
    0x13 in Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.10.2-branch/4b53fbd0/source/monodroid/src/Mono.Android/platforms/android-14/src/generated/Android.App.Activity.cs:1943 C#
    0x17 in object.3acf87a3-0149-4883-a54d-a49e8592ae4b C#

I want to know the reason for this exception. Thank you very much.

Posts

Sign In or Register to comment.