我正在使用以下代码进行自定义对话框。
我正在使用setCustomView Method的新布局。该布局包含一个“确定”按钮和一个“Cancel
”按钮。
单击取消时我需要关闭对话框。
buttonCancel.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Log.d("onClick" , "YYYYY");
//up to this comes , here what I can wright
}
});
答案 0 :(得分:0)
dialogObject.dismiss();
您可以使用此方法
答案 1 :(得分:0)
为什么不从这里创建自定义对话框:
http://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout
非常清楚地解释并且易于实施。
答案 2 :(得分:0)
试试这个:
buttonCancel.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Log.d("onClick" , "YYYYY");
qustomDialogBuilder.dismiss();//this line will close the dialog
}
});
答案 3 :(得分:0)
替换下面的TestDialogActivity
,
public class TestDialogActivity extends Activity {
private static final String HALLOWEEN_ORANGE = "#FF7F27";
private AlertDialog alertDialog;
private OnClickListener mShowDialogClickListener = new OnClickListener() {
public void onClick(View v) {
QustomDialogBuilder qustomDialogBuilder = new QustomDialogBuilder(
v.getContext())
.setTitle("Set IP Address")
.setTitleColor(HALLOWEEN_ORANGE)
.setDividerColor(HALLOWEEN_ORANGE)
.setMessage("You are now entering the 10th dimension.")
.setCustomView(R.layout.example_ip_address_layout,
v.getContext())
.setIcon(getResources().getDrawable(R.drawable.ic_launcher));
alertDialog=qustomDialogBuilder.create();
qustomDialogBuilder.setAlertDialog(alertDialog);
alertDialog.show();
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bt = (Button) findViewById(R.id.button1);
bt.setOnClickListener(mShowDialogClickListener);
}
并替换setCustomView
的{{1}},如下所示
QustomDialogBuilder
最后在您的public QustomDialogBuilder setCustomView(int resId, final Context context) {
View customView = View.inflate(context, resId, null);
((TextView)customView.findViewById(R.id.ip_text)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
((FrameLayout)mDialogView.findViewById(R.id.customPanel)).addView(customView);
return this;
}
QustomDialogBuilder
要关闭对话框,请点击private AlertDialog alertDialog;
public void setAlertDialog(AlertDialog alertDialog)
{
this.alertDialog=alertDialog;
}
文字。
答案 4 :(得分:0)
使用活动类中的QustomDialog Source here(TestDialogActivity),您可以通过设置对话框的“否定”和“正”按钮来设置“确定”和“取消”按钮,如下所示:
private OnClickListener mShowDialogClickListener =new OnClickListener(){
public void onClick(View v){
QustomDialogBuilder qustomDialogBuilder = new QustomDialogBuilder(v.getContext()).
setTitle("Set IP Address").
setTitleColor(HALLOWEEN_ORANGE).
setDividerColor(HALLOWEEN_ORANGE).
setMessage("You are now entering the 10th dimension.").
setCustomView(R.layout.example_ip_address_layout, v.getContext()).
setIcon(getResources().getDrawable(R.drawable.ic_launcher));
qustomDialogBuilder.setNegativeButton("Cancel", new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
qustomDialogBuilder.setPositiveButton("Ok", new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
/**
* Do something here...
*/
}
});
qustomDialogBuilder.show();
}
};
它看起来像这样:
希望你会发现这很有帮助。谢谢!