Karthick
Karthick

Reputation: 644

Open new Screen in Android?

Hi I am new to android. In my application if user selects the button in the alertDialog I need to open a new screen and I have to display some message on that screen. How to open a new screen?

Upvotes: 4

Views: 6610

Answers (4)

emmarbe
emmarbe

Reputation: 103

Doesn't adding this line inside the buttonhandler method of the alert dialog work?

setContentView(R.layout.screenx);

Upvotes: 0

SahanS
SahanS

Reputation: 675

Try with this,

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

btt1.setOnClickListener( View.OnClickListener() {


        public void onClick(View arg0) {

            //Starting a  Intent
            Intent next=  Intent(getApplicationContext(), second.class);

            startActivity(next);
        }       

    });

You should create btt1.setOnClickListener( View.OnClickListener() {

        public void onClick(View arg0) {

            //Starting a  Intent
            Intent next=  Intent(getApplicationContext(), pack_detail.class);

            startActivity(next);
        }       

    });

second java file look like,

public class second extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.secondx);


    }
}

and you should create secondx.xml file, and don't forget to add below statement into manifest

<activity :name=".second">  </activity>

good luck ...

Upvotes: 0

davs
davs

Reputation: 9396

comment to Erich Douglass post: and don't forget to describe it into AndroidManifest.xml like

<activity android:name=".YourNewActivity" android:label="@string/app_name" />

Upvotes: 4

Erich Douglass
Erich Douglass

Reputation: 52002

You open a new activity (i.e screen) by creating and firing off a new intent:

Intent intent = new Intent(this, YourNewActivity.class)
startActivity(intent)

Upvotes: 8

Related Questions