Android Beginner 2016 (11)--Non-blocking dialog box Alertdialog

Source: Internet
Author: User

For so long, I have seen so many controls, which seem to be static and have no interaction at all. This time, we're going to get some pinball, active.

This time continue with the previous chapter of the code to write it down.

First look at the picture


Or the nine diagram of the previous chapter, I bind the dialog box to the first icon.

Click to see the following:




Let's take a look at the code.

Package Com.fable.helloworld;  Import android.app.Activity; Import Android.app.alertdialog;import Android.content.context;import Android.content.dialoginterface;import   Android.os.Bundle; Import Android.view.view;import Android.widget.adapterview;import Android.widget.AdapterView.OnItemClickListener; Import Android.widget.gridview;import Android.widget.SimpleAdapter; Import java.util.*;p ublic class Helloworldactivity extends Activity {@Override public void onCreate (Bundle save        Dinstancestate) {super.oncreate (savedinstancestate);  Setcontentview (R.layout.activity_hello_world);                  Set main layout file GridView GridView = (GridView) Findviewbyid (R.id.gridview); Create data source arraylist

As you can see, there are three kinds of buttons in the dialog box Setpositivebutton,setneutralbutton,setnegativebutton

Literally is confirmed, neutral, denies three meanings, but these three buttons bind the event, do what is not specified, you write what event, what action can be. Of course, in order to facilitate reading, should try to conform to the original meaning.

Settitle is the activity's function, set the title

Click the button to see?



The following is an XML layout file, which, like the previous chapter, has not changed, but still sticks out:

Activity_hello_world.xml

<?xml version= "1.0" encoding= "Utf-8"?> <gridview  xmlns:android= "http://schemas.android.com/apk/res/ Android "       android:id=" @+id/gridview "      android:layout_width=" fill_parent "       android:layout_height=" fill _parent "      android:numcolumns=" Auto_fit "      android:verticalspacing=" 10DP "      android:horizontalspacing=" 10DP "      android:columnwidth=" 90DP "      android:stretchmode=" columnWidth "      android:gravity=" center "  / >  

My_list_item.xml

<?xml version= "1.0" encoding= "Utf-8"?> <relativelayout xmlns:android= "http://schemas.android.com/apk/ Res/android "android:layout_height=" wrap_content "android:paddingbottom=" 4dip "android:layout_width= "Fill_parent" > <imageview android:layout_height= "wrap_content" android:i D= "@+id/itemimage" android:layout_width= "Wrap_content" android:layout_centerhorizontal= "                  True "> </ImageView> <textview android:layout_width=" Wrap_content " android:layout_below= "@+id/itemimage" android:layout_height= "Wrap_content" an droid:text= "TextView01" android:layout_centerhorizontal= "true" android:id= "@+id/itemtext "> </TextView> </RelativeLayout>




Android Beginner 2016 (11)--Non-blocking dialog box Alertdialog

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.