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 arraylistAs 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