开发者

Open new Screen in Android?

开发者 https://www.devze.com 2022-12-31 07:49 出处:网络
Hi I am new to android. In my application if user selects the butt开发者_如何学Con 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

Hi I am new to android. In my application if user selects the butt开发者_如何学Con 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?


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)


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" />


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 ...


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

setContentView(R.layout.screenx);
0

精彩评论

暂无评论...
验证码 换一张
取 消