Android Question Adding Views From Class

AbbasMohammed

Member
Licensed User
Longtime User
Kindly, i need to add image view to the scroll view (SV) from class prod (as in the code shown below, and then i can display message like (you clicked me) when i click on this image.But the below code didnt work and i get ( java.lang.NullPointerException) message!!! So please do you have any idea to help me
Main
B4X:
Sub Globals
    Dim P As prod
    Dim SV As ScrollView:SV.Initialize (120%Y)
    SV.Panel.Color = Colors.Red
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.AddView(SV, 0,0,100%x,100%y)
SV.Panel .AddView (P.a,0,0,30%x,30%y)
End Sub
Prod Class
B4X:
Sub Class_Globals
    Public a As ImageView
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    a.Initialize ("aaa")
    a.Bitmap=LoadBitmap(File.DirAssets ,"1.jpg")
    a.Gravity =Gravity.fill
End Sub
Public Sub aaa
Msgbox("you clicked me","")
End Sub
 
Last edited:

IlCasti

Active Member
Licensed User
Longtime User
Hi
Hope this help you

Main module
B4X:
Sub Globals
    Dim P As xxx
        Dim SV As ScrollView
End Sub
Sub Activity_Create(FirstTime As Boolean)
    SV.Initialize (120%Y)
        P.Initialize(SV)
        Activity.AddView(SV, 0,0,100%x,100%y)
End Sub

Class module
B4X:
Sub Class_Globals
    Private iw As ImageView
        Private p As Panel
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(myIW As ScrollView)
    iw.Initialize ("aaa")
    iw.Bitmap=LoadBitmap(File.DirAssets ,"image.png")
    iw.Gravity =Gravity.fill
        myIW.Panel.AddView(iw,0,0,100%x,100%y)
End Sub
Public Sub iw_click
    Msgbox("you clicked me","")
End Sub

Bye
IlCasti
 
Upvote 0
Top