Simple Alert Dialog - Android

View: 107    Dowload: 0   Comment: 0   Post by: daii   Category: Mobile applications   Fields: Game - Entertainment

Download  simple-alert-dialog-android.zip (453.74 KB)

You need to Sign In to download the file simple-alert-dialog-android.zip
If you do not have an account then Sign up for free here

In this tutorial we will try to create a Simple Alert Dialog Using Android. Android is the world’s most widely used operating system with over a millions of user, that are already installed to smartphones, tablets, and even television. Android is an open source so that developer find it easy to develop and expand new features. So let's do the coding...

Getting Started:

First you will have to download & install the Android Development IDE (Android Studio or Eclipse). Android Studio is an open source development feel free to develop your things.

Here's the link for the Android Studio https://developer.android.com/studio/index.html.

Layout Design

We will now create the design for the application, first locate the activity_main.xml and click text to view the script. Then copy and paste the code below.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="<a href="http://schemas.android.com/apk/res/android"
  3. " rel="nofollow">http://schemas.android.com/apk/res/android"
  4. </a> xmlns:app="<a href="http://schemas.android.com/apk/res-auto"
  5. " rel="nofollow">http://schemas.android.com/apk/res-auto"
  6. </a> xmlns:tools="<a href="http://schemas.android.com/tools"
  7. " rel="nofollow">http://schemas.android.com/tools"
  8. </a> android:layout_width="match_parent"
  9. android:layout_height="match_parent"
  10. tools:context="com.razormist.simplealertdialog.MainActivity">
  11.  
  12.  
  13. <TextView
  14. android:layout_height="wrap_content"
  15. android:layout_width="wrap_content"
  16. android:text="Simple Alert Dialog"
  17. android:textSize="30sp"
  18. android:layout_alignParentTop="true"
  19. android:layout_centerHorizontal="true"
  20. android:layout_marginTop="20dp"
  21. android:id="@+id/tv_title"/>
  22.  
  23. android:id="@+id/btn_click"
  24. android:layout_width="wrap_content"
  25. android:layout_height="wrap_content"
  26. android:layout_centerInParent="true"
  27. android:text="Click Here"/>
  28.  
  29. </RelativeLayout>

Android Manifest File

The Android Manifest file provides essential information about your app to the Android system in which the system must required before running the code.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="<a href="http://schemas.android.com/apk/res/android"
  3. " rel="nofollow">http://schemas.android.com/apk/res/android"
  4. </a> package="com.razormist.simplealertdialog">
  5.  
  6. <application
  7. android:allowBackup="true"
  8. android:icon="@mipmap/ic_launcher"
  9. android:label="@string/app_name"
  10. android:roundIcon="@mipmap/ic_launcher_round"
  11. android:supportsRtl="true"
  12. android:theme="@style/AppTheme">
  13. <activity android:name=".MainActivity"
  14. android:configChanges="orientation"
  15. android:screenOrientation="portrait">
  16. <intent-filter>
  17. <action android:name="android.intent.action.MAIN" />
  18.  
  19. <category android:name="android.intent.category.LAUNCHER" />
  20. </intent-filter>
  21. </activity>
  22. </application>
  23. </manifest>

The Main Function

This code contains the main function of the application. This code will generate a dialog to prompt the user to what to do next when the button is clicked. To create first locate your java file and open it, then write these blocks of code.

  1. package com.razormist.simplealertdialog;
  2.  
  3. import android.app.Application;
  4. import android.content.DialogInterface;
  5. import android.support.v7.app.AlertDialog;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.util.Log;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.TextView;
  12.  
  13. public class MainActivity extends AppCompatActivity {
  14.  
  15. Button btn_click;
  16.  
  17.  
  18. @Override
  19. protected void onCreate(Bundle savedInstanceState) {
  20. super.onCreate(savedInstanceState);
  21. setContentView(R.layout.activity_main);
  22.  
  23. btn_click = (Button)findViewById(R.id.btn_click);
  24.  
  25. btn_click.setOnClickListener(new View.OnClickListener() {
  26. @Override
  27. public void onClick(View v) {
  28.  
  29. AlertDialog.Builder builder= new AlertDialog.Builder(MainActivity.this);
  30. builder.setMessage("Are you sure you want to exit?")
  31. .setTitle("System Configuration")
  32. .setCancelable(false)
  33. .setPositiveButton("YES", new DialogInterface.OnClickListener() {
  34. @Override
  35. public void onClick(DialogInterface dialog, int which) {
  36. moveTaskToBack(true);
  37. android.os.Process.killProcess(android.os.Process.myPid());
  38. System.exit(1);
  39. }})
  40. .setNegativeButton("NO", new DialogInterface.OnClickListener() {
  41. @Override
  42. public void onClick(DialogInterface dialog, int which) {
  43. dialog.cancel();
  44. }
  45. });
  46.  
  47. AlertDialog alert = builder.create();
  48. alert.show();
  49. }
  50. });
  51. }
  52. }

There you have it we successfully created a Simple Alert Dialog using android. I hope that this tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!

Simple Alert Dialog - Android

In this tutorial we will try to create a Simple Alert Dialog Using Android. Android is the world’s most widely used operating system with over a millions of user, that are already installed to smartphones, tablets, and even television. Android is an open source so that developer find it easy to develop and expand new features. So let's do the coding...

Posted on 12-03-2018 

Comment:

To comment you must be logged in members.

Files with category

  • 8-bit LED Binary Counter

    8-bit LED Binary Counter

    View: 24    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Other

    This article offers a simple implementation of the binary counter powered by Raspberry PI3 and 8 LEDs. It is very similar to what was done before for Arduino board in the previous article Connecting an Arduino to a Breadboard to Light Up LEDs. In...

  • Chat App

    Chat App

    View: 36    Download: 1   Comment: 0

    Category: Android     Fields: none

    This is a Chat App for Android mobile. You can make separate chat with you partner. I'm using Mysql Database and Php code and All APIs are develop on PHP (REST APIs). My whatsApp:+918285672453: Email ID: nirbhayiise@gmail.com

  • Tower Defense 3D

    Tower Defense 3D

    View: 25    Download: 0   Comment: 0

    Category: Android     Fields: Game - Entertainment

    The goal in this game is to protect your territory against the attacking enemies. Place defensive structures on or along their path of attack to prevent them reaching your base. Strategic choice and positioning of defensive elements is an essential...

  • Flap the Bird

    Flap the Bird

    View: 22    Download: 0   Comment: 0

    Category: Android     Fields: Game - Entertainment

    Tap your screen to make the bird fly. While you are flying there are destruction that will stop you. Avoid hitting the floor and flying to high this will deduct your life. You can collect coins and life along the way. For more mobile games and...

  • Bad Santa

    Bad Santa

    View: 28    Download: 0   Comment: 0

    Category: Android     Fields: Game - Entertainment

    This is a simple shooting game where the Bad Santa is shooting the bad snowman and reindeer. You can collect coins and life along the way. For more mobile games and tutorials you can visit this site.

  • Flappy Halloween Game

    Flappy Halloween Game

    View: 24    Download: 0   Comment: 0

    Category: Android     Fields: Game - Entertainment

    Flappy Halloween is a simple game, tap the screen to move the player. Shoot the pumpkin in the ring to gain score. Avoid hitting the flying destructions and falling from the ground. Since the Halloween is coming this game is really perfect to play...

  • Tilt Ball Game

    Tilt Ball Game

    View: 25    Download: 0   Comment: 0

    Category: Android     Fields: Game - Entertainment

    This game is simple you need to tilt your device to make the ball move in your own desired direction. Reach the finish line before the time ends and move to the next level.

  • Sky Rise 3D Game

    Sky Rise 3D Game

    View: 43    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    Stack up the blocks as high as you can to build a tower. Align the blocks on top of each other. If you manage to place the block exactly on the one before it, it will not lose size. Sloppy placement on the other hand will cut off the blocks and...

 
File suggestion for you
File top downloads
Codetitle - library source code to share, download the file to the community
Copyright © 2018. All rights reserved. codetitle Develope by Vinagon .Ltd