代号一-iOS上的掩码和取消掩码密码字段 [英] Codename One - Mask and Unmask Password Field on iOS

查看:86
本文介绍了代号一-iOS上的掩码和取消掩码密码字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TextField password = new TextField("", "Pass Word", 15, TextField.PASSWORD);
CheckBox maskAndUnmaskCheck = new CheckBox();
maskAndUnmaskCheck.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent evt) {
        if(maskAndUnmaskCheck.isSelected()) {
           password.setConstraint(TextField.ANY); 
        } else{
            password.setConstraint(TextField.PASSWORD);
        }
    }
}); 

我们正在使用上面的代码显示不带掩码的密码,即显示他输入时输入的文本用户选中该复选框。

We are using the above code to display the password without mask i.e showing the text that what he types when a user selects the check box.

以上代码在Android手机上运行正常,该代码在iPhone设备上无法运行。

The above code is working perfectly with Android mobiles, the code is not working on iPhone devices.

在iPhone上也可以实现相同的功能吗。

Is there any way to achieve the same in on iPhone too.

我需要对iOS进行任何代码更改吗?

Do I need any code changes for iOS?

推荐答案

我注意到缺少的一件事是: repaint() revalidate()

One thing I noticed that is missing there is: repaint() or revalidate().

final TextField password = new TextField("","Pass Word",15,TextField.PASSWORD);
CheckBox maskAndUnmaskCheck = new CheckBox();
maskAndUnmaskCheck.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent evt) {
        if(maskAndUnmaskCheck.isSelected()){
           password.setConstraint(TextField.ANY); 
        } else {
            password.setConstraint(TextField.PASSWORD);
        }
        if(password.isEditing()) {
            password.stopEditing();
            password.startEditingAsync();
        } else {
            password.getParent().revalidate(); 
        }
    }
}); 

这篇关于代号一-iOS上的掩码和取消掩码密码字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆