Android implements the exit dialog box and the list with Icons dialog box

Source: Internet
Author: User
Tags button type

Today we learn the content is to implement the two dialog box (Dialog), the first is to ask whether to exit the dialog box, the other is a list with the Icon dialog box, the execution effect of the program is, we click Button1, pop Up the first dialog box, when we click Button2, A different dialog box pops up.

(1) The first is the layout aspect, there are three XML files, one is the activity layout file, one is dialog layout file, one is the ListView layout file, the contents are as follows:

Activity_main.xml

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" fill_parent "    android:layout_height=" Fill_parent     " android:orientation= "vertical" >    <button android:id= "@+id/exit_button" android:layout_width= "Wrap_       Content "       android:layout_height=" wrap_content "       android:layout_gravity=" center "       android:text=" dialog box 1 "/ >        <button android:id= "@+id/list_button"       android:layout_width= "wrap_content"       android:layout_ height= "Wrap_content"       android:layout_gravity= "center"       android:text= "dialog box 2"/></linearlayout>

Dialog_list.xml

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" match_parent "    android:o rientation= "vertical" >    <listview        android:id= "@+id/listview" android:layout_width= "Fill_        Parent "        android:layout_height=" fill_parent "        android:cachecolorhint=" #00000000 ">    </listview ></LinearLayout>

Items.xml

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" match_parent "    android:o rientation= "Horizontal" >    <imageview        android:id= "@+id/image" android:layout_width= "Wrap_        Content "        android:layout_height=" wrap_content "        android:adjustviewbounds=" true "        android:maxheight=" 72px "        android:maxwidth=" 72px "        android:paddingbottom=" 20px "        android:paddingleft=" 10px        " android:paddingtop= "20px"/>    <textview        android:id= "@+id/title" android:layout_width= "Wrap_        Content "        android:layout_height=" wrap_content "        android:layout_gravity=" center "        android:padding=" 10px "/></linearlayout>

(2) Then on the Java Code section, the Code section About dialog I've been specifically staring at, specifically, see:

Package Com.example.dialogdemo;import Java.util.arraylist;import Java.util.hashmap;import android.app.Activity; Import Android.app.alertdialog;import Android.content.dialoginterface;import Android.os.bundle;import Android.view.layoutinflater;import Android.view.menu;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.viewgroup;import Android.widget.baseadapter;import Android.widget.button;import Android.widget.imageview;import Android.widget.listview;import Android.widget.textview;public class Mainactivity extends Activity {//define two static strings private static final String Dialog_icon = "Icon";p rivate static final String dialog_title = "TITLE";//the variable that declares the button type Button1private button button1;// A variable that declares a type of button Button2private button button2;//declares a variable of view type Viewprivate view view;//declares a variable of type ListView listviewprivate The ListView listview;//declares a ArrayList variable mlist, and the item inside it is the HashMap type private arraylist
(3) Perform Android project as follows:




Finally, the source code is attached:

android dialog Box (dialog) instance

Android implements the exit dialog box and the list with Icons dialog box

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.