Android: Normal dialog Box dialog

Source: Internet
Author: User

The code for the String.xml file is as follows:
1<resources>2<string name="app_name"> General dialog box Cases </string>3<string name="btn"> Show Normal dialog box </string>4<string name="title"> General dialog Box </string>5<string name="OK"> OK </string>6<string name="dialog_msg"> This is the content of the normal dialog box!!! </string>7</resources>
The Activity_common_dialog code is as follows:
1<?xml version="1.0"encoding="Utf-8"?>2<LinearLayout3Xmlns:android="http://schemas.android.com/apk/res/android"4android:orientation="Vertical"5Android:layout_width="fill_parent"6android:layout_height="fill_parent">7 8<EditText9android:text=""TenAndroid:id="@+id/eidttext01" Oneandroid:cursorvisible="false" AAndroid:layout_width="fill_parent" -android:layout_height="wrap_content"/> -  the<Button -Android:id="@+id/button01" -android:text="@string/btn" -Android:layout_width="fill_parent" +android:layout_height="wrap_content"/> -  +</LinearLayout>
The Java file code is as follows:
1 Package Com.example.sample_6_3;2 3 ImportAndroid.app.Dialog;4 ImportAndroid.content.DialogInterface;5 ImportAndroid.support.v7.app.AlertDialog;6 Importandroid.support.v7.app.AppCompatActivity;7 ImportAndroid.os.Bundle;8 ImportAndroid.view.View;9 ImportAndroid.widget.Button;Ten ImportAndroid.widget.EditText; One  APublicclassCommondialogactivity extends Appcompatactivity { -final int common_dialog = 1; - @Override the protected void OnCreate (Bundle savedinstancestate) { - super.oncreate (savedinstancestate); - Setcontentview (r.layout.activity_common_dialog); -Button BTN =(Button) Findviewbyid (r.id.button01); + Btn.setonclicklistener (New View.onclicklistener () { - @Override + Public void OnClick (View v) { AShowDialog (Common_dialog); //Show normal dialog box at             } -         }); -     } - protected Dialog oncreatedialog (int id) { -Dialog Dialog = null; //declares a dialog object for returning -Switch (ID) {//to judge an ID in Case Common_dialog: -Alertdialog.builder B =New Alertdialog.builder (this); toB.seticon (R.drawable.dialog); //Settings dialog box icon +B.settitle (R.string.title); //Setting the dialog box title -B.setmessage (R.STRING.DIALOG_MSG); //Settings dialog box display content the B.setpositivebutton ( * R.string.ok, $ New Dialoginterface.onclicklistener () {Panax Notoginseng @Override - Public void OnClick (dialoginterface dialog, int which) { theEditText et =(EditText) Findviewbyid (r.id.eidttext01); +Et.settext (R.STRING.DIALOG_MSG); //Set EditText content A                             } the                         }); +Dialog = B.create (); //Generating Dialog Objects -                  Break; $ Default: $                  Break; -         } -         returnDialog //returns the object of the production dialog the     } -}

Effects such as:

Android: Normal dialog Box dialog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.