Android Question SpotLight menu

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi. (I repost here same question posted as reply to original SpotLight post)
I am thinking to use this nice feature for displaying some country flags and doing the relative choice.
I just copied the code from Ilan example.
The difference is that I haven't put the button on a panel, but directly on activity. (In my code the "btn" button is named "Lingua").
My code is hereunder, followed by the log with the error. The program, anyway, works.
Any hint? Thanks in advance.

B4X:
Sub Globals
Private splight As SpotLight
Private Lingua AsButton
End Sub
Sub Activity_Create(FirstTime As Boolean)
 Activity.LoadLayout("Main")
 'Create Spotlight Menu
 Dim Italia,England,Russia AsBitmap' used always same jpg for the flags, just experiment 
 Italia.Initialize(File.DirAssets,"italia.jpg")
 England.Initialize(File.DirAssets,"italia.jpg")
 Russia.Initialize(File.DirAssets,"italia.jpg")
 
 splight.Initialize(Me,"splight",10%y,False,False,True,Lingua,Activity)
 
 splight.additem("Italia", Colors.Black,18,Italia)
 splight.additem("England",Colors.Black,18,England)
 splight.additem("Russia", Colors.Black,18,Russia)End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Lingua_Click
 splight.show
End Sub
LOG:

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 32 (Starter) <<<<<<<<<<<<<<<<<< ???? <<<<<<<<<<<<<
java.lang.NullPointerException: Attempt to read from field 'int android.view.ViewGroup$LayoutParams.width' on a null object reference
at anywheresoftware.b4a.objects.ViewWrapper.getWidth(ViewWrapper.java:140)
at b4a.example.spotlight._show(spotlight.java:509)
at b4a.OpenMuseum.main._lingua_click(main.java:421)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:5714)
at android.widget.TextView.performClick(TextView.java:10926)
at android.view.View$PerformClick.run(View.java:22589)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
** Activity (main) Pause, UserClosed = true **
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
 

ilan

Expert
Licensed User
Longtime User
When you initialize the spotlight menu the target view is a button in your example but it says:

Liguna.activity

What means .activity?

Just put the name of the button.
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi. Thanks for reply. The splight initialization is barely copied from the Example, namely (original code):

B4X:
Sub Globals
    Private splight As SpotLight
    Private Button1 As Button '<<<<<<<<<<<<<<<<<<<
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
   
    Dim icon As Bitmap
    icon.Initialize(File.DirAssets,"images.png")
   
    splight.Initialize(Me,"splight",10%y,False,False,True,Button1,Activity) '<<<<<<<<<<<<<<<
    splight.additem("Inbox (5)",Colors.Black,18,icon)
    splight.additem("Refresh",Colors.Black,18,Null)
    splight.additem("Compose",Colors.Black,18,Null)

I replicate here my code:
B4X:
Sub Globals
    Private splight As SpotLight
    Private Lingua As Button '<<<<<<<<<<<<<
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
    Activity.LoadLayout("Main")
  
    Dim Italia,England,Russia As Bitmap

    Italia.Initialize(File.DirAssets,"italia.jpg") ' various icons
    England.Initialize(File.DirAssets,"england.jpg")
    Russia.Initialize(File.DirAssets,"russia.jpg")
   
    splight.Initialize(Me,"splight",10%y,False,False,True,Lingua,Activity) '<<<<<<<<<<<<<<
   
    splight.additem("Italia", Colors.Black,18,Italia)
    splight.additem("England",Colors.Black,18,England)
    splight.additem("Russia", Colors.Black,18,Russia)

End Sub
The Lingua button is defined in the Layout "Main". As I wrote, anyway, the difference is that the Lingua button, as long all the Views in Main layout,have Activity as parent. In the Example, all Views are inside a Panel and have it as parent.
By the way, could the menu be displayed from top to bottom? Actually I am forced to put it at the bottom and normally the choice of language is put on the top of the screen. Thanks.
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
I am using the last version (7.00). I did "Export as zip" from b4a to get the attached file. Thanks
 

Attachments

  • omtest.zip
    20 KB · Views: 164
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
By the way I notice that two of the jpg files, namely england.jpg and russia.jpg were not included in the zip file. You can change their references in my code with italia.jpg for all the three icons. Actually, in the files folder, the two files are present. If necessary I can send them.
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi. By the way, I tried the program on another computer and got no errors.. Project is stored in "OneDrive", so I access to the same code. So, much probably, the problem is due to something wrong in the other computer. Sorry, but it happened. It remains the question of the top-bottom display, seen that you are the author. Thanks
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
everything works fine here:

Screenshot_2017-06-11-16-16-05.png


It remains the question of the top-bottom display, seen that you are the author

the answer is yes, have you seen the instruction when you initialize the spmenu?

spdown.png
 
Upvote 0
Top