我怎样才能从第二个活动转到第三个活动?

发布于 2024-12-18 19:27:22 字数 2275 浏览 0 评论 0原文

在我的 Android 应用程序中,有 3 个活动。当我单击第一个屏幕上的按钮时,它会转到第二个屏幕,单击第二个屏幕上的按钮时,它应该转到第三个屏幕。但是,当我单击第二个屏幕上的按钮时,它会转到第一个屏幕。我不知道我的代码有什么问题。

这是 CatalogueActivity

package com.Catalogue;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.content.Intent;

public class CatalogueActivity extends Activity {

    private Button button;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)  {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        this.button = (Button) this.findViewById(R.id.rdb8);
        this.button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(CatalogueActivity.this, familyevent.class);
                startActivity(intent);
            }
        });
    }
}

这是 familyevent 活动:

package com.Catalogue;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class familyevent extends Activity {
    private Button button;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.familyevent);

        this.button = (Button) this.findViewById(R.id.r1);
        this.button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent();
                intent.setClass(familyevent.this, info.class);
                startActivity(intent);
            }
        });
    }
}

这是 info 活动:

package com.Catalogue;
import android.app.Activity;
import android.os.Bundle;
public class info extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.info);
    }
}

In my android app, there are 3 activities. When I click a button on the first screen, it goes to second screen, click a button on the 2nd screen, it should go to the third. However, when I click the button on 2nd screen, it goes to the 1st screen. I don't know what is the problem in my code.

This is the CatalogueActivity:

package com.Catalogue;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.content.Intent;

public class CatalogueActivity extends Activity {

    private Button button;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)  {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        this.button = (Button) this.findViewById(R.id.rdb8);
        this.button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(CatalogueActivity.this, familyevent.class);
                startActivity(intent);
            }
        });
    }
}

This is the familyevent activity:

package com.Catalogue;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class familyevent extends Activity {
    private Button button;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.familyevent);

        this.button = (Button) this.findViewById(R.id.r1);
        this.button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent();
                intent.setClass(familyevent.this, info.class);
                startActivity(intent);
            }
        });
    }
}

This is the info activity:

package com.Catalogue;
import android.app.Activity;
import android.os.Bundle;
public class info extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.info);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

看轻我的陪伴 2024-12-25 19:27:22

分别尝试

Intent intent = new Intent().setClass(this, familyevent.class);
startActivity(intent);

Intent intent = new Intent().setClass(this, info.class);
startActivity(intent);

Try the

Intent intent = new Intent().setClass(this, familyevent.class);
startActivity(intent);

and

Intent intent = new Intent().setClass(this, info.class);
startActivity(intent);

respectivly.

掌心的温暖 2024-12-25 19:27:22

您可以尝试以下操作:

来自 CatalogueActivity:

Intent intent = new Intent(getApplicationContext(), familyevent.class);
startActvity(intent); 

和来自 familyevent:

Intent intent = new Intent(getApplicationContext(), info.class);
startActivity(intent);

希望这有效。

You can try this:

From CatalogueActivity:

Intent intent = new Intent(getApplicationContext(), familyevent.class);
startActvity(intent); 

and from familyevent:

Intent intent = new Intent(getApplicationContext(), info.class);
startActivity(intent);

hope this works.

幻想少年梦 2024-12-25 19:27:22

试试这个:

intent.setClass(this, YourNewActivity.class);

try this:

intent.setClass(this, YourNewActivity.class);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文