A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed.
Create Alert Dialog Boxes
import com.example.alertdialog.*;package com.example.alertdialog;import android.os.Bundle;import android.app.Activity;import android.app.AlertDialog;import android.content.DialogInterface;import android.content.Intent;import android.view.Menu;public class MainActivity extends Activity {import android.view.View;protected void onCreate(Bundle savedInstanceState) {@Overridesuper.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}public void open(View view){AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);alertDialogBuilder.setMessage(R.string.decision);alertDialogBuilder.setPositiveButton(R.string.positive_button,new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface arg0, int arg1) {Intent positveActivity = new Intent(getApplicationContext(),com.example.alertdialog.PositiveActivity.class);startActivity(positveActivity);}});alertDialogBuilder.setNegativeButton(R.string.negative_button,new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {Intent negativeActivity = new Intent(getApplicationContext(),com.example.alertdialog.NegativeActivity.class);startActivity(negativeActivity);}});AlertDialog alertDialog = alertDialogBuilder.create();alertDialog.show();}@Overridepublic 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;}}
No comments:
Post a Comment