46th: Android Dialog dialog box (iii)

Source: Internet
Author: User

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)

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.