none
error CS0117: 'Resource.Id' does not contain a definition for 'id' RRS feed

  • Question

  • C# code:
    using Android.App;
    using Android.Widget;
    using Android.OS;
    using Android.Support.V7.App;
    
    namespace SimpleCalc
    {
        [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
        public class MainActivity : AppCompatActivity
        {
    
            TextView txtNumber;
    
            int number;
    
            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);
    
                // Set our view from the "main" layout resource
                SetContentView(Resource.Layout.activity_main);
    
                txtNumber = FindViewById<TextView>(Resource.Id.txtNumber);
    
                FindViewById<Button>(Resource.Id.btnIncrement).Click += (o, e) =>
                    txtNumber.Text = (++number).ToString();
    
                FindViewById<Button>(Resource.Id.btnDecrement).Click += (o, e) =>
                    txtNumber.Text = (--number).ToString();
            }
        }
    }
    
    
    AXML:
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TextView
            android:text="0"
            android:textSize="50sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="20dp"
            android:gravity="center"
            android:id="@+id/txtNumber" />
        <Button
            android:text="Add"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/textView1"
            android:id="@+id/btnIncrement" />
        <Button
            android:text="Subtract"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/button1"
            android:id="@+id/btnDecrement" />
    </RelativeLayout>

    Tuesday, May 8, 2018 10:57 PM

Answers

All replies

  • Hi SkilledDev,

    Thank you for posting here.

    For your question is more related to Android, please post a new thread in StackOverFlow.

    https://stackoverflow.com/questions/tagged/android

    The Visual C# forum discuss and ask questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 9, 2018 2:17 AM
    Moderator
  • Save .axml & Build Project Again.

    • Marked as answer by SkilledDev Wednesday, May 9, 2018 12:23 PM
    Wednesday, May 9, 2018 2:56 AM
  • It worked! Thank you for your help!
    Wednesday, May 9, 2018 12:24 PM