Apply for Zend Framework Certification Training

Android




<p>Step 1 D:\Users\Rajesh\AndroidStudioProjects\CustomAlert\app \src\main\res\layout\activity_main.xml <!--?xml version="1.0" encoding="utf-8"?--> Step 2 D:\Users\Rajesh\AndroidStudioProjects\CustomAlert\app\src\main\ java\com\example\rajesh\customalert\MainActivity.java package com.example.rajesh.customalert; import android.content.Context; import android.content.DialogInterface; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { final Context context = this; private Button button; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button) findViewById(R.id.buttonAlert); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); alertDialogBuilder.setTitle(&quot;Are You sure you want Close this App !&quot;); alertDialogBuilder .setMessage(&quot;Click yes to exit!&quot;) .setCancelable(false) .setPositiveButton(&quot;Yes&quot;,new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { MainActivity.this.finish(); } }) .setNegativeButton(&quot;No&quot;,new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } }); } }</p>
                                    

< How to pass Data From One Activity to Another Activity in android Remove Title bar from Android screen >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top