Android Question b4xFloatTextField defined in layout not initialized

Discussion in 'Android Questions' started by Rusty, May 24, 2019.

  1. Rusty

    Rusty Well-Known Member Licensed 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:
    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can always use two B4XPreferenceDialog objects.

    However it does sound like a bug. Can you upload a small project that demonstrates it?
     
  3. Rusty

    Rusty Well-Known Member Licensed 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
     

    Attached Files:

  4. Erel

    Erel Administrator Staff Member Licensed 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)
     
  5. Rusty

    Rusty Well-Known Member Licensed 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:
     

    Attached Files:

  6. Erel

    Erel Administrator Staff Member Licensed User

    I'm pretty sure that the error happens in the code that you modified. I've previously thought that you are clearing the items and it then causes some problem. If you think that this is the case then upload an example based on B4XPreferencesDialog unmodified library.
     
  7. Rusty

    Rusty Well-Known Member Licensed 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.
    Code:
    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:
    Code:
    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?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    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:
    Code:
    If B4xFld.TextField.Parent.IsInitialized And B4xFld.TextField.Parent.parent.IsInitialized Then
     ...
     
  9. Rusty

    Rusty Well-Known Member Licensed 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
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    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:
    I thought that it happens with the standard unmodified class. This issue is clearly related to the changes you made.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice