Android Question Can I add a buttom to a map?

grafsoft

Well-Known Member
Licensed User
Longtime User
Hi,

I have several buttons in a photo and I need to maake the clicked button blinking. I now how to do that, but for that I need the button as an object.

I hope the code speaks for itself.

Thanks

B4X:
Sub Globals
   dim pointlist as list
end sub

Sub Activity_Create(FirstTime As Boolean)
    pointlist.initialize
end sub

...
' add the button to a map and the map to a list
   Dim m As Map
   m.Initialize
   m.Put("no",no)
   m.Put("x",x)
   m.Put("y",y)
   m.Put ("btn",b) ' b is a button
   If pointlist.IndexOf (m) = -1 Then
     pointlist.Add (m)

   End If


Sub touchbtn_click
   Dim Send As Button
  Send=Sender
  clickedno=Send.tag
   clickedbtn=Sender
    msgbox (clickedbtn.Left, clickedbtn.Top) ' here I get a null pointer exception
' search for the button in the list
   Dim m As Map
   Dim i As Int
   For i=0 To pointlist.Size-1
     m=pointlist.get (i)
     Dim no As Int
     no=m.Get ("no")
     ' Msgbox (no,clickedno)
     If no=clickedno Then
       clickedbtn=m.Get ("btn")
       msgbox (clickedbtn.Left, clickedbtn.Top) ' here I get a null pointer exception


     End If
   Next

' this is what I want to do
Sub timer2_tick
   clickedbtn.SetColorAnimated (1000,Main.ptealcolor,Colors.red)   ' won't work
 
Last edited:

grafsoft

Well-Known Member
Licensed User
Longtime User
"Button" instead of "btn"? Does not work.
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewGroup$LayoutParams com.phillipcalvin.iconbutton.IconButton.getLayoutParams()' on a null object reference
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You need to use the objectname you defined....

If you named the variable for this button "wilhelm" then
B4X:
Map.Put("Button", wilhelm)
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
Yes, of course. The rest of the code works, the buttons are diesplayed, which means they exist.

B4X:
   Dim b As IconButton
   Dim rad As Int = 40dip
   b.initialize ("touchbtn")
   b.tag=no
   Dim c As Int
   c=Main.a100color
   Dim cd As ColorDrawable
   cd.Initialize (c,rad)
   b.Background=cd
   
   bd.Initialize(Basis.CreateScaledBitmap2(LoadBitmap(File.DirAssets, "ic_microphone_black_48dp.png"), 40dip, 40dip, True))
  b.setIcon(False, bd)
   
  pnlDrawing.addview (b,x-rad/2,y-rad/2,rad,rad)

   
   Dim m As Map
   m.Initialize
   m.Put("no",no)
   m.Put("x",x)
   m.Put("y",y)
   m.Put ("IconButton",b)
...
[Code]
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
The funny thing is, when I put the cursor on "m" after this line
B4X:
 m=pointlist.get (i)
the variable m has a value "Iconbutton" and Inconbutton has also values. Therefore it should exist too.
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
It seems that the details disappear when I do an addview:

B4X:
 b.setIcon(False, bd)
' here, in debug mode, I have all the info and variables   
  pnlDrawing.addview (b,x-rad/2,y-rad/2,rad,rad)
' here, they are gone
 
Upvote 0
Top