You have to put the code of your second listing in the OnClickListener
of one of your buttons (I guess you want it to be executed after the Ok button is pressed):
...
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String newString = input.getText().toString();
if(newString.equals("2")) {
System.out.print("lol");
}
}
});
...
You cannot expect to get the user input immediately after the dialog is shown. The user simply does not have time to type anything.