Search code examples
xamarin.androidfindviewbyid

FindViewByID in Xamarin.Android is not recognizing the ID defined in the ..axml


I am new to Xamarin. I have created EditText item in Content_main.xaml. Source code for EditText is below

<EditText
    android:id = "@+id/inputBill"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

In the main CS file, I am trying to get the value from EditText element via its ID. Sample Code below

    EditText inputBill1;
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        Xamarin.Essentials.Platform.Init(this, bundle);
        SetContentView(Resource.Layout.Content_main);
        inputBill1 = FindViewById<EditText>(Resource.Id.inputBill);

Getting below error "'Resource.Id' does not contain a definition for 'inputBill'"

Please let me know If i am missing any thing.


Solution

  • 1. Make that the Resource is your namespace.Resource

    2. Ignore the error message of VS, continue to build (it's vs tools's problem,always notice id can not find, but you can still run)

    3. If still not work after the above two points, delete the content inside the "Resources/Resource.Designer.cs" file, and then rebuild (delete the contents of the file, not delete the file)