Skip to main content

how to make an alert message in android

  Alert box code-activity.xml       <? xml version ="1.0" encoding ="utf-8" ?> <RelativeLayout xmlns: android ="http://schemas.android.com/apk/res/android"     xmlns: app ="http://schemas.android.com/apk/res-auto"     xmlns: tools ="http://schemas.android.com/tools"     android :layout_width ="match_parent"     android :layout_height ="match_parent"     app :layoutDescription ="@xml/activity_main_scene"     tools :context =".MainActivity" >     <TextView         android :id ="@+id/textView"         android :layout_width ="wrap_content"         android :layout_height ="wrap_content"          />     <Button         android :id ="@...

how to make an alert message in android

 

Alert box code-activity.xml

 

 

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:app="http://schemas.android.com/apk/res-auto"
   
xmlns:tools="http://schemas.android.com/tools"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
app:layoutDescription="@xml/activity_main_scene"
   
tools:context=".MainActivity">

    <TextView
       
android:id="@+id/textView"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
        
/>

    <Button
       
android:id="@+id/button2"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:layout_marginBottom="43dp"
       
android:onClick="showAlert"

       
android:text="Button" />


</RelativeLayout>

Java coding

package com.example.test;

import
androidx.appcompat.app.AppCompatActivity;
import
android.app.AlertDialog;
import
android.content.DialogInterface;
import
android.os.Bundle;
import
android.view.View;
import
android.widget.Button;

import
android.os.Bundle;

public class
MainActivity extends AppCompatActivity {

   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
       
setContentView(R.layout.activity_main);
       
Button alertButton = findViewById(R.id.button2);
       
alertButton.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
                showAlert()
;
           
}
        })
;
   
}


   
public void showAlert() {
        AlertDialog.Builder builder =
new AlertDialog.Builder(this);
       
builder.setTitle("Alert");
       
builder.setMessage("This is an alert message");
       
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
           
@Override
           
public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss()
;
            
}
        })
;

       
AlertDialog alertDialog = builder.create();
       
alertDialog.show();
   
}
}

 

Comments

Popular posts from this blog

Why did Steve jobs visit India?

  SteveJobs dropped out of Reed College and joined the videogame company. Jobs wanted to earn money. Because for his Reed collegemate Robert Friedland visited India for a spiritual journey. Friedland knew Neem Karoli Baba, who had been the guru to much of the sixties Hippie Movement. Jobs wanted to visit India for enlightenment, and he travelled to India with his friend Daniel Kottke. Jobs arrived NewDelhi.He drank unfiltered water because the hotel owner told a lie to him that unfiltered water was filtered water. So He had a severe fever and dysentery.       After recovery, he wanted to get out of New Delhi. He went to Haridwar, near the source of the Ganges. At this point, a great Hindu Festival, Kumbha Mela celebrated there. A lot of holy men around there. There were People riding Elephants. Jobs decided to get out there too. He went to a village near Nainital, in the foothills of the Himalayas. There Neem Karoli Baba lived. At the point Jobs got there, Baba ...

Steve Jobs and Bill Gates in a personal computer Age

    Two College dropouts person worked in the personal computer age just like a binary star system. Jobs dropped out of college to find enlightenment, but a lawyer's son BillGates dropped out of Harward to start a computer software company. Jobs stared at people with burning and wounding, but Gates had trouble making eye contact with people. Jobs and Gates are opposite characters. When the Macintosh was underdeveloped, Jobs went to Gates at his office. Microsoft wrote some applications for Apple 2. Microsoft accepted his project with the code-named SAND(Steve Amazing New Device). Jobs wanted Microsoft to write an application program for Macintosh that is word and spreadsheet. Gates sighed a graphical version of a new spreadsheet called Excel. Word processing is known as Microsoft word. Gates's Microsoft company applications worked in Machintosh. Each application rate is $10 per computer. Microsoft's application was attached to the mac with the apple logo. Microsoft makes so...