45th: Android Dialog dialog box (ii)

Source: Internet
Author: User

Only down-to-earth people can say: road, at my feet.


This content: Dialog dialog box


Example three: information content is a simple view type

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 ("Please enter"). SetIcon (     android. R.drawable.ic_dialog_info). Setview (     new EditText (This)). Setpositivebutton ("OK", null)     . Setnegativebutton ("Cancel", null). Show ();}}

here is the result of the operation:



message content is a set of radio boxes

Below 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 ("Radio Box"). SetIcon (     android. R.drawable.ic_dialog_info). Setsinglechoiceitems (     new string[] {"Male", "female"}, 0,//0 Default check male, 1 default female     new Dialoginterface.onclicklistener () {public      void OnClick (dialoginterface dialog, int which) {       Dialog.dismiss () ;      }     }). Setnegativebutton ("Cancel", null). Show ();}}

here is the result of the operation:



message content is a set of multi-box

Below 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 ("check box"). Setmultichoiceitems (     new string[] {"Item1", "ITEM2"}, NULL, NULL).     Setpositivebutton ("OK", null).     Setnegativebutton ("Cancel", null). Show ();}}

here is the result of the operation:



This is about here, take your time and enjoy it

45th: Android Dialog dialog box (ii)

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.