JohnA
JohnA

Reputation: 594

How do I view a new window C# Android

im trying to change window when the "EASY" (easyBtn) is being pressed, I basically want the current window to change into a new one with a few other buttons, but I really have no clue on what the code should look like, im used to the .NET framework. (Im new to Android Developing)

--QUESTION--
So how do I view a new window when the "EASY" button is being pressed?

Here is my current code (As you will see I got kinda stuck.

namespace The_Coder_Quiz
{
    [Activity(Label = "The_Quiz", 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);



            //EasyBtn

            Button easyBtn = FindViewById<Button>(Resource.Id.easyBtn);
            easyBtn.Click += (object sender, EventArgs e) => {


                //this button will generate a new empty window when being pressed




            };
        }
    }
}

I tried adding a RelativeLayout and connecting the button to it so it changes on keypress but I couldnt find any code examples to learn from. Picture

Upvotes: 0

Views: 199

Answers (2)

Dasser Basyouni
Dasser Basyouni

Reputation: 3252

you should create a new xml (and that is the design of the new window you will go to) and also new class and extends its code to AppComppact and ovrride onCreate method by ctrl+o and set its contentView the new xml like that :

package example.gsdfgsdf.gadfgsfgs;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.YourNewXML);
    }

and also declare the that Activity (xml and class) in the manifest.xml like that

        <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <activity
            android:name=".YourDesiredActivityApperedNameInApp"
            android:label="YourNewXMLAppearedNameInTheNavBar"/>
    </activity>

and set the button on click in the main xml like that

<Button
    android:id="@+id/Btn7_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="YourNewOnClickMethode"
    android:text="7"/>

and create the onClick in the main Activity (you are on now) like that

public void YourNewOnClickMethode(View view) {
    Intent intent = new Intent(this, YourNewClass.class);
    startActivity(intent);
}

Upvotes: 0

libertylocked
libertylocked

Reputation: 912

Sounds like you are trying to start another activity.

You need to create a new Activity (right click your Project, select "Add Item" and click Activity) Then

button.Click += delegate {
   StartActivity(typeof(Activity2));
};

See https://developer.xamarin.com/recipes/android/fundamentals/activity/start_an_activity/

Upvotes: 1

Related Questions