Created
April 10, 2013 11:49
-
-
Save leonguyen/5353961 to your computer and use it in GitHub Desktop.
Android Lab: Alert Dialog - Create Alert Dialog program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example.androidlab; | |
| import android.os.Bundle; | |
| import android.app.Activity; | |
| import android.app.AlertDialog; | |
| import android.content.Context; | |
| import android.content.DialogInterface; | |
| import android.view.Menu; | |
| import android.view.View; | |
| import android.view.View.OnClickListener; | |
| import android.widget.Button; | |
| public class MainActivity extends Activity { | |
| final Context context = this; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| Button button = (Button) findViewById(R.id.buttonAlertDialog); | |
| // Add button listener | |
| button.setOnClickListener(new OnClickListener() { | |
| public void onClick(View arg0) { | |
| AlertDialog.Builder builder = new AlertDialog.Builder(context); | |
| builder.setTitle("About") | |
| .setMessage("This is Alert Dialog!") | |
| .setPositiveButton("Close", | |
| new DialogInterface.OnClickListener() { | |
| public void onClick(DialogInterface dialog, | |
| int id) { | |
| dialog.cancel(); | |
| } | |
| }); | |
| ; | |
| AlertDialog dialog = builder.create(); | |
| dialog.show(); | |
| } | |
| }); | |
| } | |
| @Override | |
| public boolean onCreateOptionsMenu(Menu menu) { | |
| // Inflate the menu; this adds items to the action bar if it is present. | |
| getMenuInflater().inflate(R.menu.main, menu); | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment