简体   繁体   English

如何从弹出窗口进入新活动?

[英]How to go to a new activity from a pop up?

I created a pop up to confirm a package and when the user selects the "confirm" button it should take the user to another activity but it is not working properly. 我创建了一个弹出窗口来确认一个包,当用户选择“确认”按钮时,它应该让用户进行另一个活动,但它无法正常工作。

Here is my code: 这是我的代码:

switch (v.getId()) {
        case R.id.button_solicitar:
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setCancelable(true);
            builder.setTitle("Confirmación");
            builder.setMessage("¿Deseas solicitar " + sum + " toallas con un total de $" + tot1 + " pesos?");
            builder.setPositiveButton("Confirmar",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(Paquetes.this, "¡Tu pedido ha sido solicitado!", Toast.LENGTH_LONG).show();
                            startActivity(new Intent(this, Casa.class));
                        }
                    });
            builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });
            AlertDialog dialog = builder.create();
            dialog.show();
            break;

Try change 尝试改变

startActivity(new Intent(this, Casa.class));

to

startActivity(new Intent(YourActivity.this, Casa.class)); //YourActivity is the class name of your current Activity

这样做

startActivity(new Intent(getApplicationContext(), Casa.class));

Try , 试试吧,

startActivity(new Intent(Paquetes.this, Casa.class));    // assuming your current activity is Paquetes

if it doesn't work can you post your error log once? 如果它不起作用,你可以发布一次错误日志吗?

Please run your application in debug mode.Check if it is stopping at startActivity(new Intent(this, Casa.class)).If not please post your logcat. 请在调试模式下运行您的应用程序。检查它是否在startActivity停止(new Intent(this,Casa.class))。如果没有,请发布您的logcat。

One more thing Please check your manifest: 还有一件事请检查您的清单:

Have you declared your Activity Casa.class in manifest file: 您是否在清单文件中声明了您的Activity Casa.class:

<activity android:name=".Casa" >

If nothing is working out I request you to post your logcat. 如果没有什么工作,我请求你发布你的logcat。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM