[英]Open a new activity within an alertdialog in Android Studio
我希望在 alertDialog 中啟動一個新活動,但是從我使用 startActivity 或創建新意圖的那一刻起,我的 alertDialog 按鈕就會出現錯誤並關閉整個應用程序。
這個想法是,如果用戶選擇“選擇名稱”選項,他會打開一個新的 Intent,其中包含另一個名為“ChangeNameView.class”的 Activity,並在 alertDialog 中使用另一個布局。
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();
}
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?
我沒有在 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.