none
No Text or Buttons Showing - Xamarin RRS feed

  • Question

  • I am trying to show buttons and text on my main activity, but nothing is showing up when running on an Asus Zenfone 2 on Debug Mode (Solution Configuration). Here is my code. I am using Xamarin. Thanks in advance.

    MainActivity.cs

    using System;
    using Android.App;
    using Android.Widget;
    using Android.OS;
    
    namespace MusicHistory1.Droid
    {
        [Activity(Label = "Music History 1 Quiz", MainLauncher = true, Icon = "@drawable/icon")]
        public class MainActivity : Activity
        {
            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);
    
                // Set our view from the "main" layout resource
                SetContentView(Resource.Layout.Main);
                // Get the UI controls from the loaded layout:
                Button btnAPeople = FindViewById<Button>(Resource.Id.btnAPeople);
                Button btnComposer = FindViewById<Button>(Resource.Id.btnComposer);
                Button btnEra = FindViewById<Button>(Resource.Id.btnEra);
                Button btnTerms = FindViewById<Button>(Resource.Id.btnTerms);
                Button btnWorks = FindViewById<Button>(Resource.Id.btnWorks);
                Button btnAll = FindViewById<Button>(Resource.Id.btnAll);
                EditText txtMoo = FindViewById<EditText>(Resource.Id.txtmoo);
                // String telling it which quiz it should open
                int strquizchoice;
                btnAPeople.Click += (object sender, EventArgs e) =>
                {
                    strquizchoice = 0;
                    StartActivity(typeof(PlayActivity));
                };
                btnComposer.Click += (object sender, EventArgs e) =>
                {
                    strquizchoice = 1;
                    StartActivity(typeof(PlayActivity));
                };
                btnEra.Click += (object sender, EventArgs e) =>
                {
                    strquizchoice = 2;
                    StartActivity(typeof(PlayActivity));
                };
                btnTerms.Click += (object sender, EventArgs e) =>
                {
                    strquizchoice = 3;
                    StartActivity(typeof(PlayActivity));
                };
                btnWorks.Click += (object sender, EventArgs e) =>
                {
                    strquizchoice = 4;
                    StartActivity(typeof(PlayActivity));
                };
                btnAll.Click += (object sender, EventArgs e) =>
                {
                    strquizchoice = 5;
                    StartActivity(typeof(PlayActivity));
                };
    
            }
        }
    }

    Main.axml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
      <Button
          android:text="@string/APeople"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/btnAPeople" />
      <Button
          android:text="@string/Composer"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/btnComposer" />
      <Button
          android:text="@string/Era"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/btnEra" />
      <Button
          android:text="@string/Terms"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/btnTerms" />
      <Button
          android:text="@string/Work"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/btnWorks" />
      <Button
          android:text="@string/All"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/btnAll" />
      <TextView
        android:text="moo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/txtmoo" />
    </LinearLayout>

    Sunday, June 25, 2017 9:33 PM

All replies

  • Hi Cow124,

    Thank you for posting here.

    According to your question is more related to Xamarin, you could post a new thread in Xamarin forum for suitable support.

    This forum discuss and ask 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.


    Monday, June 26, 2017 2:25 AM