To harness the rudder of destiny is to struggle. Do not have a glimmer of imagination, do not give up a little opportunity, do not stop working hard.
This content: Dialog dialog box
Example six: Information content is a set of simple list items
Here is the Mainactivity.java main interface file:
public class Mainactivity extends activity{private Button b; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); b= (Button) Findviewbyid (R.id.button) ; B.setonclicklistener (New View.onclicklistener () {@Overridepublic void OnClick (View arg0) {Dialog ();}});} private void Dialog () {new Alertdialog.builder (this). Settitle ("list box"). Setitems ( new string[] {"Item1", "Item2"}, NULL). Setnegativebutton ( "OK", null). Show ();}}
here is the result of the operation:
Example VII: information content is a custom layout
Here is the new Res/layout/dialog.xml layout file:
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Match_ Parent " android:layout_height=" match_parent " android:id=" @+id/dialog "> <textview android : id= "@+id/tv1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android: text= "Name:"/> <edittext android:id= "@+id/edit" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content"/></linearlayout>
here is the Mainactivity.java main interface file:
public class Mainactivity extends activity{private Button b; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); b= (Button) Findviewbyid (R.id.button) ; B.setonclicklistener (New View.onclicklistener () {@Overridepublic void OnClick (View arg0) {Dialog ();}});} private void Dialog () {Layoutinflater inflater = Getlayoutinflater (); View layout = Inflater.inflate (R.layout.dialog, (ViewGroup) Findviewbyid (R.id.dialog)); New Alertdialog.builder (this). Settitle ("Custom Layouts"). Setview (Layout) . Setpositivebutton ("OK", null) . Setnegativebutton ("Cancel", null). Show ();}}
here is the result of the operation:
This is where we go, take your time and enjoy it
46th: Android Dialog dialog box (iii)