AldoT AldoT - 7 months ago 8
Java Question

How to go/pass 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 I am doing something wrong and I can not do so. Can you help me please?

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;


Thanks in advance!

Answer

do like this

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