Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. package project.login;
  2.  
  3. import android.app.Activity;
  4. import android.app.AlertDialog;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.view.View.OnClickListener;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10.  
  11. public class LoginActivity extends Activity {
  12. /** Called when the activity is first created. */
  13. @Override
  14. public void onCreate(Bundle icicle) {
  15. super.onCreate(icicle);
  16. setContentView(R.layout.main);
  17. Button launch = (Button)findViewById(R.id.login_button);
  18.  
  19. launch.setOnClickListener( new OnClickListener ()
  20. {
  21. public void onClick(View view)
  22. { EditText usernameEditText = (EditText) findViewById(R.id.username);
  23. EditText passwordEditText = (EditText) findViewById(R.id.password);
  24.  
  25. String sUsername = usernameEditText.getText().toString();
  26. String sPassword = passwordEditText.getText().toString();
  27.  
  28. if(usernameEditText == null || passwordEditText == null) {
  29. new AlertDialog.Builder(this)
  30. .setTitle("Error")
  31. .setMessage("You can't let the fields empty")
  32. .show();
  33. }
  34. }
  35.  
  36. }
  37. );
  38. }
  39.  
  40. }
  41.  
  42. new AlertDialog.Builder(LoginActivity.this)
  43. .setTitle("Error")
  44. .setMessage("You can't let the fields empty")
  45. .show();
  46.  
  47. Don't forget to import android.app.AlertDialog first.
  48.  
  49. AlertDialog alert = new AlertDialog.Builder(this).create();
  50. alert.setTitle("Error");
  51. alert.setMessage("Sorry, your device doesn't support flash light!");
  52. alert.setButton(Dialog.BUTTON_POSITIVE,"OK",new DialogInterface.OnClickListener(){
  53.  
  54. @Override
  55. public void onClick(DialogInterface dialog, int which) {
  56. finish();
  57. }
  58. });
  59.  
  60. alert.show();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement