After installing the app, an alertDialog
will pop-out. I wanted it to have a edit text field asking for the name of the user. After answering, it will never show again. Then afterwards, every time I open the app, another alertDialog
will pop-out like a greeting to the user.
public class MainActivity extends Activity {
final Context context = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Welcome");
alert.setMessage("Enter Your Name Here");
final EditText input = new EditText(context);
alert.setView(input);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
AlertDialog alertDialog = alert.create();
alertDialog.show();
AlertDialog.Builder a_builder = new AlertDialog.Builder(MainActivity.this);
a_builder.setMessage("Mabuhay!")
.setCancelable(true)
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = a_builder.create();
alert.show();
}
}