Android interface ---- custom Dialog, and then use the callback method to process the events of buttons in the Dialog

Source: Internet
Author: User

Package com. demo;
 
Import android. app. Dialog;
Import android. content. Context;
Import android. OS. Bundle;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. Button;
 
Public class LeaveMeetingDialog extends Dialog implements OnClickListener {
 
Private Button quitBtn, stopBtn, cancelBtn;
Private LeaveMeetingDialogListener listener;
 
Public interface LeaveMeetingDialogListener {
Public void onClick (View view );
}
 
Public LeaveMeetingDialog (Context context, int theme, LeaveMeetingDialogListener listener ){
Super (context, theme );
}
 
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. leave_meeting_dialog );
InitViews ();
}
 
Private void initViews (){
QuitBtn = (Button) findViewById (R. id. quit_btn );
StopBtn = (Button) findViewById (R. id. stop_btn );
CancelBtn = (Button) findViewById (R. id. cancel_btn );
 
QuitBtn. setOnClickListener (this );
StopBtn. setOnClickListener (this );
CancelBtn. setOnClickListener (this );
}
 
@ Override
Public void onClick (View v ){
Listener. onClick (v );
}
 
}

--- Call:

[Java]
LeaveMeetingDialog dialog = new LeaveMeetingDialog (this, R. style. Theme_CustomDialog,
New LeaveMeetingDialogListener (){
@ Override
Public void onClick (View view ){
Switch (view. getId ()){
Case R. id. quit_btn: break;
Case R. id. stop_btn: break;
Case R. id. cancel_btn: break;
}
}
});
Dialog. show ();

 

 

From liuxiIT's column

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.