当前位置: 首页 > 知识库问答 >
问题:

单击肯定按钮后仍显示对话框

解修然
2023-03-14

我有一个按钮(CustomDilaog活动),当点击显示自定义对话框和密码编辑文本,确定按钮和取消按钮时,如果你输入正确的密码,它会打开另一个活动(文本活动),直到现在一切正常,

我有两个部分的问题。

第一部分:当我在(文本活动)并按后退按钮返回(CustomDilaog活动)时,仍然对话框显示在它上面,如何让它关闭

第二部分:对话框启动后,如果我不写密码,只需单击“确定”按钮,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();
      }
    });
}
}

共有2个答案

林念
2023-03-14

第一部分:当我在(文本活动)并按后退按钮返回(CustomDilaog活动)时,仍然对话框显示在它上面,如何让它关闭

启动新的活动时,只需在您的CustomDialogActivity中调用finish()。看起来您的意图是调用相同的活动,但我对此有点困惑。

if( password.getText().toString().length() > 0 ) {
       if( password.getText().toString().equals("test")) {
            Intent intent = new Intent(CustomDilaog.this,Text.class);
            startActivity(intent);

第二部分:对话框启动后,如果我不写密码,只需单击“确定”按钮,edittext为空,它就没有响应,如何让此单击“只需关闭”对话框而不执行任何操作(如果写了正确的密码,则此对话框是打开的(文本活动))。

在第一个if对话框中添加一条else语句,并将其放入对话框中。Disclose()

欧阳嘉年
2023-03-14

调用对话框。Disclose()在dialogButton的开头单击listener:

dialogButton.setOnClickListener(new OnClickListener() {
   public void onClick(View v) {

      dialog.dismiss();

      EditText password = (EditText) dialog.findViewById(R.id.password);
      if( password.getText().toString().length() > 0 ) {

      ...
   }
});
 类似资料:
  • 链接到我正在尝试刮取的页面: https://www.nytimes.com/reviews/dining 因为这个页面有一个“show more”按钮,所以我需要Selenium自动反复单击“show more”按钮,然后以某种方式使用Beauty soup来获取页面上每个餐厅评论的链接。在下面的照片中,我想获取的链接位于https://...onigiri.html" 迄今为止的代码: 我如何

  • 问题内容: 这是一个滑块难题。拼图完成后,我想显示一个带有“确定”按钮的对话框。当按下“确定”按钮时,我使用来通过Android浏览器加载网站。唯一的问题是,使用当前代码,当拼图完成后,它不会加载一个框(当我使用时会加载)。它什么也没做。有任何想法吗? 问题答案: 试试这个

  • 按钮点击页面后刷新并重定向到另一个页面。在我的情况下,点击按钮后,我给页面刷新超时,但点击按钮后,它显示超时异常,没有时间等待。 例外: 失败:createEventTest组织。openqa。硒。TimeoutException:等待页面加载时超时。命令持续时间或超时:15.08秒构建信息:版本:“2.53.0”,修订版:“35ae25b1534ae328c771e0856c93e187490c

  • 在我的angular应用程序中,我正在尝试添加功能,当我单击Windows图像时,一个新的对话框窗口将显示3个单选按钮。我需要帮助来添加此功能 这是stackblitz链接 链接-https://stackblitz.com/edit/angular-yvinp9?file=src/app/app.component.ts

  • 当用户单击返回按钮时,我正在尝试退出应用程序,让它在单击是按钮时显示对话框是/否按钮,让它退出应用程序,包括注册活动,假设您在主活动上。 这是我的代码,但它不工作 单击主活动上的“后退”按钮时 如何从主活动退出应用程序,包括在是按钮单击对话框上的注册活动

  • 我已经创建了一个警报对话框构建器,其中正在显示一个表单的对话,我的积极按钮名称是提交,我希望按钮被禁用,除非表单中的所有字段都被填满。下面是我的代码,任何人可以帮助我在这方面的工作。谢谢