简体   繁体   English

在 Android Studio 的警报对话框中打开一个新活动

[英]Open a new activity within an alertdialog in Android Studio

I am looking to start a new activity within alertDialog, but from the moment I use startActivity or create a new intent, my alertDialog button gives a bug and closes the entire app.我希望在 alertDialog 中启动一个新活动,但是从我使用 startActivity 或创建新意图的那一刻起,我的 alertDialog 按钮就会出现错误并关闭整个应用程序。

The idea is that if the user chooses the option "Choose Name" he opens a new Intent with the other Activity called "ChangeNameView.class" with another layout inside the alertDialog.这个想法是,如果用户选择“选择名称”选项,他会打开一个新的 Intent,其中包含另一个名为“ChangeNameView.class”的 Activity,并在 alertDialog 中使用另一个布局。

NewMeasureScreen.class NewMeasureScreen.class

private void opcaoPilhaUser() {
    final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
    alertDialog.setTitle("Deseja inserir um novo nome para pilha ou escolher um já existente?");

    //Em caso afirmativo o usuário insere uma novo nome para pilha e uma nova lista.
    alertDialog.setPositiveButton("INSERIR", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            newMeasureDialog();
        }
    });

    //Em caso afirmativo o usuário insere um nome de uma pilha já existente através de uma lista.
    alertDialog.setNegativeButton("ESCOLHER NOME", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();  //Ele só finaliza a janela atual.
            startActivity(new Intent(NewMeasureScreen.this,ChangeNameView.class));

        }
    });

    //Em caso neutro sair do app e ir para TELA INICIAL DO APP e não registrar nenhum valor.
    alertDialog.setNeutralButton("CANCELAR", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            finish();
        }
    });

    //Volta para a primeira tela "HomeScreen" caso o botão de voltar no celular seja pressionado

    alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialogInterface) {
           finish();
        }
    });

    //Mostrar janela.
    alertDialog.show();

}

ChangeNameView.class更改名称View.class

public class ChangeNameView extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.screen_nome_existente);
        fullScreen();
    }

    private void fullScreen() {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
}

Process: br.com.visit.hammerhead2, PID: 13408 android.content.ActivityNotFoundException: Unable to find explicit activity class {br.com.visit.hammerhead2/br.com.visit.hammerhead2.ChangeNameView}; have you declared this activity in your AndroidManifest.xml?

I had not declared a ChangeNameView activity in AndroidManifest.xml, so now I have declared it.我没有在 AndroidManifest.xml 中声明 ChangeNameView 活动,所以现在我已经声明了它。

<activity android: name = ". ChangeNameView"
            android: label = "Hammerhead2"
            android: screenOrientation = "landscape"
            android: theme = "@ style / AppTheme" />

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

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