Android Question b4xFloatTextField defined in layout not initialized

Rusty

Well-Known Member
Licensed User
Longtime User
I am trying to load a layout within the PreferencesDialog based upon a previous PreferencesDialog selection.

i.e. Dialog 1 - I would like to sign up? (Boolean view), if they select True, load a new dialog that has b4xFloatTextFields for name, address...etc.

Currently, the Boolean layout works fine at level one. ALSO, the name, address,...JSON works fine if it is the FIRST layout to be loaded. However, when I clear the first dialog and try to load the second one (name, address...), the first b4xFloatTextField view, which is loaded with the textitem.bal (from Erel's example), I get the error:
DecorView setVisiblity: visibility = 8, Parent = ViewRoot{32c8a97 b4a.formstest/b4a.formstest.main,ident = 2}, this = DecorView@c377b51[]
Class not found: b4a.example.b4xfloattextfield, trying: b4a.formstest.b4xfloattextfield
Error occurred on line: 407 (B4XFloatTextField)
java.lang.RuntimeException: Object should first be initialized (B4XView).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:69)
at anywheresoftware.b4a.objects.B4XViewWrapper.getParent(B4XViewWrapper.java:166)
at b4a.formstest.clspreferencesdialog._b4xfloattextfield1_textchanged(clspreferencesdialog.java:1346)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1083)
at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:1046)
at b4a.formstest.b4xfloattextfield._tf_textchanged(b4xfloattextfield.java:985)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.objects.EditTextWrapper$1.afterTextChanged(EditTextWrapper.java:83)
at android.widget.TextView.sendAfterTextChanged(TextView.java:8576)
at android.widget.TextView.setText(TextView.java:4548)
at android.widget.TextView.setText(TextView.java:4396)
at android.widget.EditText.setText(EditText.java:95)
at android.widget.TextView.setText(TextView.java:4371)
at android.widget.TextView.setTransformationMethod(TextView.java:1976)
at android.widget.TextView.applySingleLine(TextView.java:8242)
at android.widget.TextView.setSingleLine(TextView.java:8217)

Please note that this works fine if I load this JSON file FIRST, but the link to the second dialog, I'm missing something that will allow me to remove the first dialog and then create a new dialog.
I'm using Erel's example and extending it.

Any advice will be appreciated.
Rusty
 

Rusty

Well-Known Member
Licensed User
Longtime User
The problem with defining multiples is that when I implement this, there will be dozens of different JSON files to load and manage. I don't think creating a new B4XPreferenceDialog for each one will be a good thing.
Attached, please find a small project. I've modified your code for the clsPreferenceDialog.bas (included) to allow events for validation.
Thanks for your kind, continued support :)
Rusty
 

Attachments

  • FormsTest.zip
    39.3 KB · Views: 196
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm getting errors:

at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1761)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6642)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy (ignored)**
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Permission finished
Key allowaddpatient value: false
Error occurred on line: 153 (Main)
java.io.FileNotFoundException: /storage/emulated/0/survey/options.map (No such file or directory)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:308)
at java.io.FileOutputStream.<init>(FileOutputStream.java:238)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:448)
at anywheresoftware.b4a.objects.streams.File.WriteBytes(File.java:432)
at b4a.formstest.main._savedata(main.java:837)
at b4a.formstest.main$ResumableSub_ShowPrefDialog.resume(main.java:966)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1761)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6642)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Sorry, when I cut my example program copy, I failed to copy the folder creation routines. Since they already existed on my device I did not notice the lack of code...
Here you are:
 

Attachments

  • FormsTest.zip
    39.4 KB · Views: 208
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Loading the two different JSON's works within your library code. However, I don't have the validation events I need to use the dialog library.

In my code:
I commented out the events (Callsub to Main) and the JSON's load correctly.

I am not clear as to why the events cause this.
B4X:
Private Sub B4XFloatTextField1_EnterPressed
    Dim B4xFld As B4XFloatTextField
    B4xFld = Sender
    Dim edtText As EditText = B4xFld.TextField
    Dim p As B4XView = B4xFld.TextField.Parent.parent
    Dim tg As B4XPrefItem = p.Tag
    If SubExists(Main, "Text_EnterPressed") Then
        CallSub3(Main, "Text_EnterPressed", edtText, tg)
    End If
End Sub

private Sub B4XFloatTextField1_TextChanged (Old As String, New As String)     'text/multiline text
    Dim B4xFld As B4XFloatTextField
    B4xFld = Sender
    Dim p As B4XView = B4xFld.TextField.Parent.parent
    Dim This As TxtItem
    This.Tag = p.Tag
    This.Old = Old
    This.New = New
    Log("TEXT CHANGED " & Old & "   new " & New)        'also password
    If SubExists(Main, "Text_Changing") Then
        CallSub2(Main, "Text_Changing", This)
    End If
End Sub

The line in the b4xPreferencesDialog causing the problem (with the events defined) is p.LoadLayout("textitem") below:
B4X:
Private Sub CreateLayouts (pi As B4XPrefItem) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    p.Width = CustomListView1.sv.ScrollViewContentWidth
    p.Height = 50dip
    Select pi.ItemType
        Case TYPE_BOOLEAN
            p.LoadLayout("booleanitem")
            Dialog.InternalSetTextOrCSBuilderToLabel(p.GetView(0), pi.Title)
            p.GetView(0).TextColor = TextColor
            p.GetView(0).Tag = pi
        Case TYPE_MULTILINETEXT
            p.Height = pi.Extra.Get("height")
            p.LoadLayout("textitemmulti")
            p.Tag = pi
            Dim ft As B4XFloatTextField = p.GetView(0).Tag
            ft.HintText = pi.Title
            ft.Update
        Case TYPE_TIME
            CreateTimeItem(pi, p)
        Case TYPE_NUMERICRANGE
            CreateNumericRangeItem(pi, p)
        Case TYPE_TEXT, TYPE_PASSWORD, TYPE_NUMBER, TYPE_DECIMALNUMBER
            p.Height = 60dip
          
            If pi.ItemType = TYPE_PASSWORD Then
                p.LoadLayout("passworditem")
                p.Tag = pi
            Else
                p.LoadLayout("textitem")
                p.Tag = pi
                Dim ft As B4XFloatTextField = p.GetView(0).Tag
                If pi.ItemType = TYPE_NUMBER Then
                    #if B4A ...

Is there a way to re-enable the event(s) after the dialog is cleared so that they still function?
Should I re-dimension the class?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is there a way to re-enable the event(s) after the dialog is cleared so that they still function?
I cannot really answer without learning the changes you made to the class. As it is not a simple class it is not simple to answer.

It should be simple to solve the error message you posted. You can add a check in TextChanged event:
B4X:
If B4xFld.TextField.Parent.IsInitialized And B4xFld.TextField.Parent.parent.IsInitialized Then
 ...
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Sorry, I thought I sent you the clsPreferencesDialog.bas in the zip file...
It's in the zip file from post #5. Let me know if it won't unzip or is corrupt and I'll resend it.
Thanks for your help on this...


Rusty
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Sorry, I thought I sent you the clsPreferencesDialog.bas in the zip file..
You did send it. However for me to help you I need to run a 'diff' tool on this large class and find all the changes you made. I also need to learn why you made those changes and understand them. Only then I would be able to help with this specific problem. This is not something that I can do. Sorry.

When I wrote:
However it does sound like a bug. Can you upload a small project that demonstrates it?
I thought that it happens with the standard unmodified class. This issue is clearly related to the changes you made.
 
Upvote 0
Top