Codename One - Mask and Unmask Password Field on iOS

只谈情不闲聊 提交于 2020-01-02 08:57:11

问题


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.

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

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

Do I need any code changes for iOS?


回答1:


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(); 
        }
    }
}); 


来源:https://stackoverflow.com/questions/42807405/codename-one-mask-and-unmask-password-field-on-ios

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!