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 ...

How did the Indian subcontinent join to Asian Continent?

                                                    1                                      Indian subcontinent   Continent Drift Today Indian subcontinent is located in the Indian Ocean and Asian continent. But, the Indian subcontinent Once was attached between Africa and Madagascar. In 1912 Alfred Wegener invented continental drift. Before the twelfth century, people believed the continent had not moved. " The Origin of Ocean and continent"   was written by Alfred Wegener.       He explains present continents gathered in a single land mass that later drifted apart. So our world map shows a jigsaw puzzle shape with different continents and countries that appeared like they could fit each other. These countries are far apart, but their...