alertdialog looks good, but maybe the error is in the rest of the code. You should keep in mind that you cannot use var playerName, just run the show () dialog box if you want to print the name you need to make using runnable, which you call here:
static Handler handler = new Handler();
[.......]
public void onClick(DialogInterface dialog, int whichButton) {
playerName = input.getText().toString();
handler.post(set_playername);
}
[.......]
static Runnable set_playername = new Runnable(){
@Override
public void run() {
}
};
edit to clarify:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setMessage("Your Name");
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
playerName = input.getText().toString();
}
});
alert.show();
source
share