Click events

Ksmith1192

Member
Licensed User
Longtime User
Hi guys, simple question here.

I was just wondering if you could make a click event within a sub.

I know I can do Sub btn_click and tell it what to do, but I need it to be within the Sub of something else. All i need to add is for the following to happen:

If Imageview1 is clicked, then Imageview1 gets removed.

Thanks guys!
 

enonod

Well-Known Member
Licensed User
Longtime User
I believe that if in the click sub for imageview you say xxx.RemoveView it will happen. That is how I have done it with Panels, so I can see no difference. Try that and see.
 
Upvote 0

Ksmith1192

Member
Licensed User
Longtime User
I dont have the sub click for the imageview. it is under a different sub, and I cant remove it properly unless it is removed from that other sub
 
Upvote 0

grant1842

Active Member
Licensed User
Longtime User
As enonod said:

B4X:
Sub ImageView1_Click
     ImageView1.RemoveView
End Sub

What doesn't work?
 
Upvote 0

Ksmith1192

Member
Licensed User
Longtime User
This is the code i have, i am trying to get rid of the Imageview1 from pnlPie.
B4X:
Sub Graphbtn_click
Activity.AddView(TabHost1, 0, 0, 100%x, 100%y)

Dim p As Panel
Dim PD As PieData
p.Initialize("")
pnlPie.Initialize("pnlPie")
' p.AddView(pnlPie, 0, 0, 100%x, 100%y - 100dip)
p.AddView(pnlPie, 0, 0, 100%x, 100%y - 100dip)
TabHost1.AddTab2("", p) '"Pie Chart"

PD.Initialize

PD.Target = pnlPie
 'Set the target view
'Add the items. The last parameter is the color. Passing 0 will make it a random color.
Charts.AddPieItem(PD, Emaciated, 5, 0)
Charts.AddPieItem(PD, Thin, 10, 0)
Charts.AddPieItem(PD, Heavy, 20, 0)
Charts.AddPieItem(PD, Fat, 30, 0)
Charts.AddPieItem(PD, Average, 35, 0)
PD.GapDegrees = 5 'Total size of gaps between slices. Set to 0 for no gaps.


PD.LegendBackColor =Colors.ARGB(150, 100, 100, 100) 'The background color of the legend bitmap.
Dim legend As Bitmap
'This call draws the pie.
'PD - The pie data
'Colors.Gray - The view's background color
'True - Create a legend bitmap.
legend = Charts.DrawPie(PD, Colors.Gray, True)
Dim ImageView1 As ImageView
ImageView1.Initialize("")
ImageView1.SetBackgroundImage(legend)

pnlPie.AddView(ImageView1, 10dip, 10dip, legend.Width, legend.Height)

End Sub
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
It should work as said, you need to type in the click event sub as shown. Clicking will remove the view from pnlpie. yes/no
 
Upvote 0

Ksmith1192

Member
Licensed User
Longtime User
I tried it this way
Sub Imageview1_click
pnlPie.RemoveView(ImageView1)
End Sub

but i got this error message
Error description: Object reference not set to an instance of an object.
Occurred on line: 233
pnlPie.RemoveView(ImageView1)
Word: (
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
B4X:
Dim ImageView1 As ImageView
-Should be a Global Variable - in Sub Globals

B4X:
ImageView1.Initialize("")
- Would normally be in Activity Create, and should be:

B4X:
ImageView1.Initialize("ImageView1")
, then ImageView1_Click will be called when ImageView1 is clicked.
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
@Ksmith1192
The line you needed in the imageview1 click sub was... imageview1.RemoveView
That removes itself. You can find the explanation in the Help.exe under any view or when entering the code the tooltip should tell you.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…