当单击显示自定义对话框时,我有按钮(CustomDilaog 活动),带有密码编辑文本和确定按钮和取消按钮,如果输入正确的密码,它会打开另一个活动(文本活动),直到现在一切正常,
我对两部分有疑问。
第一部分:当我在(文本活动)并按后退按钮返回(CustomDilaog活动)时,对话框仍然显示在它上面,如何让它消失
第二部分:在对话框触发后,如果我不写密码并且只点击 OK 按钮,edittext 为空它没有响应,如何让这个点击只是关闭对话框而不采取任何行动(如果写了正确的密码,它是打开的(文本活动)。
(CustomDilaog 活动):
public class CustomDilaog extends Activity {
final Context context = this;
private Button button;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv=(TextView)findViewById(R.id.introclusion_tv1);
tv.setTypeface(FontFactory.getBFantezy(getBaseContext()));
TextView tv1=(TextView)findViewById(R.id.introclusion_tv2);
tv1.setTypeface(FontFactory.getBFantezy(getBaseContext()));
tv1.setText(Html.fromHtml(getString(R.string.introclusion)));
button = (Button) findViewById(R.id.button1);
// add button listener
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// custom dialog
final Dialog dialog = new Dialog(context,R.style.cust_dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom);
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.text);
Typeface font = Typeface.createFromAsset(getAssets(), "BFantezy.ttf");
text.setTypeface(font);
text.setText("write password :");
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
Typeface font1 = Typeface.createFromAsset(getAssets(), "BFantezy.ttf");
dialogButton.setTypeface(font1);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText password = (EditText) dialog.findViewById(R.id.password);
////
if( password.getText().toString().length() > 0 ) {
if( password.getText().toString().equals("test")) {
Intent intent = new Intent(CustomDilaog.this,Text.class);
startActivity(intent);
}
else{
// get your custom_toast.xml layout
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) findViewById(R.id.custom_toast));
// set a dummy image
ImageView image = (ImageView) layout.findViewById(R.id.image_toast);
image.setImageResource(R.drawable.ic_launcher);
// set a message
TextView text = (TextView) layout.findViewById(R.id.text_toast);
text.setText("Wrong password");
// Toast...
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
}
}
});
Button dialogButtonCancell = (Button) dialog.findViewById(R.id.cancel);
Typeface font11 = Typeface.createFromAsset(getAssets(), "BFantezy.ttf");
dialogButtonCancell.setTypeface(font11);
dialogButtonCancell.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
}
}