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

Indo-Soviet relationship

Mitrokhin Archive -Special Relationship with India(Indo-Soviet Relationship) Mitrokhin Archive -2 book's 17 and 18 chapter describes The special relationship with India. It represented the Indo-Soviet relationship during the cold war and KGB measurements in Indian politics.                                                       Indo-Soviet Relationship-Nehru period      During the cold war, KGB concentrated on the third-world country India. Stalin and his followers thought India was an Imperialist Puppet. The great Soviet encyclopedia dismissed Mohandas Mahathma Gandhi as a reactionary who betrayed the people and helped imperialism against them. Despite his distaste, the Stalinists attacked Jawaharlal Nehru. They regarded Nehru as a reactionary like Gandhi.KGB penetrated the Indian embassy during 1950-1960.         ...