Android Question Password in an EditText

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi all.

Edit text has a property Password that you can check on and off in Designer.
Then if I generate it as Edittext I can turn on and off the PasswordMode

But if I generate it as B4XView this option is missing in a code

Is there any way how to di it in a code?

My client has asked me to do it the similar way when you enter a phone password when you click on an eye and you see the whole text you entered.
 
Last edited:

William Lancee

Well-Known Member
Licensed User
Longtime User
B4XView is just a wrapper for the view it contains.

B4X:
EditText1.As(EditText).PasswordMode = True

So you can turn it on and off in code.
You do have to provide your own 'Eye' button!

B4XFloatTextfield does have an eye incorporated. Try that as you input field. It is pretty good.
 
Upvote 1

Daestrum

Expert
Licensed User
Longtime User
Can similar be done in B4J? (which is where I tried it, because I don't have B4A with me here)
Most B4XViews can be cast back to their original and vice versa.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
@Daestrum is correct.

There is no EditText in B4J. The Textfield can be defined as password in designer. But I can't do it in code.
This doesn't work.
B4X:
    TextField1.As(Textfield).InitializePassword("xx")

If you do it in designer, it also doesn't have an eye.

However B4XFLoatTextfield is cross platform and works fine.
This custom contains a Textfield so I wonder how B4XFloatTextfield does it?
 
Upvote 0

emexes

Expert
Licensed User
Most B4XViews can be cast back to their original and vice versa.

Agreed, but the (sub)issue is that the B4J equivalent of B4A EditText does not show a Password property:
(although it does have a checkbox for it in Designer)

1708900964564.png
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
I looked at the source code of B4XFloatTextfield. It is all done explicitly. Here is an excerpt.

B4X:
Private Sub CreateRevealButton
    lblClear = CreateButton(Chr(0xE8F4))
    lblClear.Tag = "reveal"
End Sub

Private Sub SwitchFromPasswordToRegular (ToRegular As Boolean)
    Dim text As String = mTextField.Text
    Dim textcolor As Int = mTextField.TextColor
    Dim Font1 As B4XFont = mTextField.Font
    Dim oldfield As B4XView = mTextField
    
    CreateTextFieldAll(Not(ToRegular), Font1, textcolor)
    mTextField.Text = text
    If lblClear.IsInitialized Then
        If ToRegular = False Then
            lblClear.Text = Chr(0xE8F4)
            lblClear.Tag = "reveal"
        Else
            lblClear.Tag = "hide"
            lblClear.Text = Chr(0xE8F5)
        End If
        lblClear.BringToFront
    End If
    '....'
End Sub
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
The reveal code leads to this...

B4X:
        Dim tf As TextField
        If Password Then tf.InitializePassword("tf") Else tf.Initialize("tf")

Try this in B4j. The password will be revealed in 5 seconds.
B4X:
    Dim tf As TextField
    tf.InitializePassword("event")
    tf.Text = "abcdef"
    Root.AddView(tf, 100, 400, 300, 50)
   
    Sleep(5000)
   
    Dim text As String = tf.text
    tf.RemoveNodeFromParent
    Dim tf As TextField
    tf.Initialize("event")
    tf.Text = text
    Root.AddView(tf, 100, 400, 300, 50)
 
Upvote 0
Top