Android界面之----自定义的Dialog,然后利用回调方法,在调用处,进行Dialog中各按钮的事件处理
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 inte易做图ce 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);
}
}
---调用处:
[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();
摘自 liuxiIT的专栏
补充:移动开发 , Android ,