В моем файле main.class
есть простой текст кода, который создает диалог popup
. Когда я пытаюсь закрыть popupdialog с помощью метода finish();
, он закрывает все приложение, а не только всплывающее диалоговое окно. Как я могу решить это? (это для Android, посмотрите мои комментарии ниже также.)
Это код:
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.start_dialog);
dialog.setTitle("This is my custom dialog box");
dialog.setCancelable(true);
//there are a lot of settings, for dialog, check them all out!
//set up text
TextView text = (TextView) dialog.findViewById(R.id.TextView01);
text.setText(R.string.loss);
//set up image view
ImageView img = (ImageView) dialog.findViewById(R.id.ImageView01);
img.setImageResource(R.drawable.golf_ball);
//set up button
Button button = (Button) dialog.findViewById(R.id.Button01);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
//now that the dialog is set up, it's time to show it
dialog.show();