I want to hide MainActivity
when AlertDialog
is shown. I create new Activity and put my code in it and call it from MainActivity
by using Intent
.
My Code of AlertDialog
:
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
public class Dialog extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AlertDialog.Builder builder1 = new AlertDialog.Builder(Dialog.this);
builder1.setTitle("RONQ");
builder1.setMessage(MainActivity.mesgList.get(MainActivity.currentMsgNumber));
builder1.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder1.show();
}
}
And Intent
code is:
Intent intent = new Intent();
intent.setClass(MainActivity.this, Dialog.class);
startActivity(intent);
You don't need Intent :
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("message")
.setPositiveButton(getString(R.string.update), (dialogInterface, i) -> {
//do something
}).setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
//do something
}).setCancelable(false).create().show();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.