Android Question searchview error while calling from b4xpage

elitevenkat

Active Member
Licensed User
Longtime User
ref https://www.b4x.com/android/forum/t...native-to-autocompleteedittext.19379/#content

the above link sample is working in activity form. when i try to run from b4xpage, it says the following error message. What could be the problem ?

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
 
    ime.Initialize("ime")
    ime.AddHeightChangedEvent
    Root = Root1
    Root.LoadLayout("groupslist")



Logger connected to: samsung SM-G615F
--------- beginning of crash
--------- beginning of main

Error occurred on line: 69 (SearchView)
java.lang.RuntimeException: Object should first be initialized (ListView).
Did you forget to call Activity.LoadLayout?
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at anywheresoftware.b4a.objects.ListViewWrapper.Clear(ListViewWrapper.java:197)
at b4a.example.searchview._et_textchanged(searchview.java:224)
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:10745)
at android.widget.TextView.setText(TextView.java:6059)
at android.widget.TextView.setText(TextView.java:5876)
at android.widget.EditText.setText(EditText.java:143)
at android.widget.TextView.setText(TextView.java:5833)
at android.widget.TextView.setTransformationMethod(TextView.java:2944)
at android.widget.TextView.applySingleLine(TextView.java:10373)
at android.widget.TextView.setInputType(TextView.java:6331)
at anywheresoftware.b4a.objects.EditTextWrapper.setInputType(EditTextWrapper.java:187)
at b4a.example.searchview._initialize(searchview.java:280)
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.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:61)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
at b4a.example.groups$ResumableSub_B4XPage_Created.resume(groups.java:114)
at b4a.example.groups._b4xpage_created(groups.java:64)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1055)
at b4a.example.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:1023)
at b4a.example.b4xpagesmanager._showpage(b4xpagesmanager.java:413)
at b4a.example.b4xpages._showpage(b4xpages.java:109)
at b4a.example.b4xpage3._lviewdrawer_itemclick(b4xpage3.java:583)
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$1.run(BA.java:352)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7025)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
 

DonManfred

Expert
Licensed User
Longtime User
I don´t see how you are accessing the listview in your incomplete codesnippet.

How should one help here?
 
Upvote 0

elitevenkat

Active Member
Licensed User
Longtime User
My code

i have incuded searchview class in the project

B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    
    Private SearchView1 As SearchView
    Private ime As IME
    Private index As Object
    Private lstAll As ListView
    Private pnlsearch As Panel
End Sub

'You can add more parameters here.
Public Sub Initialize

End Sub

'''This event will be called once, before the page becomes visible.

Private Sub B4XPage_Created (Root1 As B4XView)
 
    ime.Initialize("ime")
    ime.AddHeightChangedEvent
    Root = Root1
    Root.LoadLayout("groupslist")
     
    Dim cities As List = File.ReadList(File.DirAssets, "Cities.txt")
    'As an optimization we store the index as a process global variable
    'and only build it once.
    index = SearchView1.SetItems(cities)
     
    SearchView1.SetIndex(index)

  
End Sub

error shown in searchview module
B4X:
Private Sub et_TextChanged (Old As String, New As String)
    lv.Clear        --------------------------------------------------------- This Line
    If lv.Visible = False Then lv.Visible = True
    If New.Length < MIN_LIMIT Then Return
    Dim str1, str2 As String
    str1 = New.ToLowerCase
    If str1.Length > MAX_LIMIT Then
        str2 = str1.SubString2(0, MAX_LIMIT)
    Else
        str2 = str1
    End If
    AddItemsToList(prefixList.Get(str2), str1)
    AddItemsToList(substringList.Get(str2), str1)
End Sub
 
Upvote 0

elitevenkat

Active Member
Licensed User
Longtime User
try adding sleep(0) after loading the Layout
No did not work. Worked when i changed as follows.
B4X:
Private Sub et_TextChanged (Old As String, New As String)
    lv.Clear        
    If lv.Visible = False Then lv.Visible = True 
    If New.Length < MIN_LIMIT Then Return      --------------------------------------------------------- This Line i took it on top
    Dim str1, str2 As String
    str1 = New.ToLowerCase
    If str1.Length > MAX_LIMIT Then
        str2 = str1.SubString2(0, MAX_LIMIT)
    Else
        str2 = str1
    End If
    AddItemsToList(prefixList.Get(str2), str1)
    AddItemsToList(substringList.Get(str2), str1)
End Sub
 
Upvote 0

elitevenkat

Active Member
Licensed User
Longtime User
BTW, there is a better implementation in B4XDialog + B4XSearchTemplate.
I searched the forum, lot of quires related to b4xsearchtemplate could be found, unable locate a simple example showing the usage (tutorial) of b4xsearchtemplate. Can anyone send the link plz
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1:
B4X:
Private Dialog As B4XDialog
Private Search As B4XSearchTemplate

2:
B4X:
Dialog.Initialize(Root)
Dialog.Title = "Example"
Search.Initialize
Search.SetItems(Array("aaa", "bbb", "ccc", "ddd", "eee"))
3:
B4X:
Sub btnSearch_Click
    Wait For (Dialog.ShowTemplate(Search, "", "", "Cancel")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Log(Search.SelectedItem)    
    End If
End Sub

Sub B4XPage_CloseRequest As ResumableSub
    If Dialog.Visible Then
        Dialog.Close(xui.DialogResponse_Cancel)
        Return False
    End If
    Return True
End Sub
 
Upvote 0
Top