Implementing Alert Messages and User Input Handling in Java

Slide Note
Embed
Share

This tutorial guides you through creating alert messages, handling user input, defining functions, calling functions from the `onCreate` method, and creating an XML file for user data entry validation in Java. Learn how to display alerts for empty user credentials and process user actions accordingly.


Uploaded on Aug 08, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Alert Message Dr. Sandip Mal

  2. Design XML File

  3. Edit Java File Declare Button Variable private Button b; o public void OnClickListener(){ b=(Button)findViewById(R.id.button); b.setOnClickListener( new View.OnClickListener(){ @Override public void onClick(View v) { AlertDialog.Builder b=new AlertDialog.Builder(MainActivity.this); b.setMessage("Do you want to close the apps").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog alert=b.create(); alert.setTitle("Alert!!!"); alert.show(); } } ); } Define the function

  4. Call the Function from onCreate method

  5. Assignment Create one XML file contains userid, password and submit button. If userid and password are blank and you press submit button then alert button will be displayed with blank userid or password message. If you put userid and password it will display user id and password in the alert message.

Related