1. Download our Official Android App: Forums for Android!

from one screen to another

Discussion in 'Android Apps & Games' started by lenelarsen26, Jan 2, 2013.

  1. lenelarsen26

    lenelarsen26 Lurker
    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    2
    Joined:
    Jan 2, 2013

    Jan 2, 2013
    2
    0
    25
    Hi
    I have made a copy off an App found on the Internet. Android activity – from one screen to another screen
    My version doesn't work. When I right click on my projekt, choose Run As, and Android Application, the virtual device starts ok, but nothing happens.
    What can be wrong?
    Here is my App:
    package​
    com.example.lene;

    import​
    android.app.Activity;

    import​
    android.content.Context;

    import​
    android.content.Intent;

    import​
    android.os.Bundle;

    import​
    android.view.View;

    import​
    android.view.View.OnClickListener;

    import​
    android.widget.Button;

    public​
    class AppActivity extends Activity {

    Button
    button;

    @Override

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.
    main);
    addListenerOnButton();
    }

    public void addListenerOnButton() {

    final Context context = this;

    button = (Button) findViewById(R.id.button1);

    button.setOnClickListener(new OnClickListener() {

    @Override

    public void onClick(View arg0) {

    Intent intent =
    new Intent(context, App2Activity.class);
    startActivity(intent);

    }

    });

    }

    }
    package​
    com.example.lene;

    import​
    android.app.Activity;

    import​
    android.os.Bundle;

    import​
    android.widget.Button;

    public​
    class App2Activity extends Activity {

    Button
    button;

    @Override

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.
    main2);
    }

    }
    <?​
    xml version="1.0" encoding="utf-8"?>
    <
    LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@+id/linearLayout1"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:eek:rientation="vertical" >


    <TextView

    android:id="@+id/textView1"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="I&apos;m screen 1 (main.xml)"

    android:textAppearance="?android:attr/textAppearanceLarge" />


    <Button

    android:id="@+id/button1"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:text="Click me to another screen" />

    </LinearLayout>
    <?​
    xml version="1.0" encoding="utf-8"?>
    <
    LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:eek:rientation="vertical" >

    <TextView

    android:id="@+id/textView1"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="I&apos;m screen 2 (main2.xml)"

    android:textAppearance="?android:attr/textAppearanceLarge" />



    </LinearLayout>
    <?​
    xml version="1.0" encoding="utf-8"?>
    <
    manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.example.lene"

    android:versionCode="1"

    android:versionName="1.0" >


    <uses-sdk android:minSdkVersion="10" />





    <application

    android:icon="@drawable/ic_launcher"

    android:label="@string/app_name" >

    <activity

    android:label="@string/app_name"

    android:name=".AppActivity" >

    <intent-filter>

    <action android:name="android.intent.action.MAIN" />


    <category android:name="android.intent.category.LAUNCHER" />

    </intent-filter>

    </activity>

    <activity

    android:label="@string/app_name"

    android:name=".App2Activity" >

    </activity>


    </application>

    </manifest>
     

    Advertisement

Share This Page

Loading...