如何在屏幕之间切换? [英] How to switch between screens?

查看:45
本文介绍了如何在屏幕之间切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是android开发领域的新手.我创建了一个简单的应用程序,并使用一个按钮创建了一个简单的GUI.如果用户按下此按钮,我想将屏幕更改为显示其他GUI.

I'm new in the android develop world. I created simple application and created a simple GUI with one button. If the user presses this button, I want to change the screen to show some other GUI.

我该怎么做?

推荐答案

您执行以下代码:

public class Activity1 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button next = (Button) findViewById(R.id.Button01);
    next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), Activity2.class);
            startActivityForResult(myIntent, 0);
        }

    });
}
}

活动2:

public class Activity2 extends Activity {

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main2);

    Button next = (Button) findViewById(R.id.Button02);
    next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent intent = new Intent();
            setResult(RESULT_OK, intent);
            finish();
        }

    });
}

还请确保在布局文件夹中创建2个不同的xml ,并在清单文件中添加两个活动,例如

<activity android:name=".Activity2"></activity>

希望这会对您有所帮助.

Hope this will help you.

这篇关于如何在屏幕之间切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆