Dialog and toast for Android Development

Source: Internet
Author: User

Public class mainactivity extends activity {

@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. activity_main );

Button btn1 = (button) findviewbyid (R. Id. button1 );
Btn1.setonclicklistener (New View. onclicklistener (){

@ Override
Public void onclick (view v ){
// Todo auto-generated method stub
Toast. maketext (getapplicationcontext (), R. String. Success, Toast. length_long). Show ();
Alertdialog. Builder = new alertdialog. Builder (mainactivity. This );
Builder. setmessage (R. String. Message)
. Settitle (R. String. Title)
. Setpositivebutton (R. String. OK, new dialoginterface. onclicklistener (){

@ Override
Public void onclick (dialoginterface arg0, int arg1 ){
// Todo auto-generated method stub

. Setnegativebutton (R. String. Cancel, new dialoginterface. onclicklistener (){

@ Override
Public void onclick (dialoginterface dialog, int which ){
// Todo auto-generated method stub

. Seticon (R. drawable. ic_launcher );
Dialog dialog = builder. Create ();
Dialog. Show ();


@ Override
Public Boolean oncreateoptionsmenu (menu ){
// Inflate the menu; this adds items to the action bar if it is present.
Getmenuinflater (). Inflate (R. Menu. Main, menu );
Return true;


Related Article

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.