Android Question How add FloatLabeledEditText via code ?

dws

Member
Licensed User
Longtime User
Hello there,

I hava problem when create FloatLabeledEditText with code.

Message Error
java.lang.RuntimeException: Object should first be initialized (FloatLabeledEditText).

My code is like this ...

B4X:
' The hosting panel for B4XView
Dim p As Panel

' The b4xview control
Dim xV As B4XView

' Add the FloatLabeledEditText with code (not with designer) and initialize
Dim txtEdit As FloatLabeledEditText
txtEdit.Initialize("txtEdit")

' Assign to b4xview with some properties
xV = txtEdit
xV.Color = xui.PaintOrColorToColor(Colors.Yellow)

' Add b4xview to hosting panel
p.AddView(xV, 0,0,0,0)

...
 

DonManfred

Expert
Licensed User
Longtime User
The correct way do add a customview is using Layouts.

Create a layout with just the floatedit.

Load this layout to any panel you need a floating edit in.
 
Upvote 0

dws

Member
Licensed User
Longtime User
Thanks DonManfred.
I know that. This is my last choice.

I just want to be able to use it within the code of a controller I build which you design with code.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
see this
 
Upvote 0

dws

Member
Licensed User
Longtime User
Thanks Star-Dust.

Some clarifications
I have created a library that contains some controls. The present control until recently had EditText as the word processing field in my control.
You design the control directly with code or by entering Custom to the designer.
I wanted to change EditText to one of the Floats ... in order to avoid adding an extra Label as a caption to the control.

Results
A. With FloatLabeledEditText it gives me an error for Initialize in the control
B. With B4XFloatTextField and BRB4XFloatTextField it gives me an error to Initialize in B4XView.

Any suggestion or comment accepted ... Thank you
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Thanks Star-Dust.

Some clarifications
I have created a library that contains some controls. The present control until recently had EditText as the word processing field in my control.
You design the control directly with code or by entering Custom to the designer.
I wanted to change EditText to one of the Floats ... in order to avoid adding an extra Label as a caption to the control.

Results
A. With FloatLabeledEditText it gives me an error for Initialize in the control
B. With B4XFloatTextField and BRB4XFloatTextField it gives me an error to Initialize in B4XView.

Any suggestion or comment accepted ... Thank you
If you want to replace EditText with B4XFloatTextField , you can't just do it from code by simply replacing the declaration as you thought.

You have to replace each EditText on the design with B4XFloatTextField and then edit the code. Obviously by inserting from Design you don't have to initialize it. If you want to do everything from code you have to look at the link I indicated, but it is not easy.
 
Upvote 0

dws

Member
Licensed User
Longtime User
Hello Erel and thanks to your response. I solved my problem with adding label to my control to simulate Floating Label inside.
 
Upvote 0
Top