Android Question get all buttons in a panel(solved)

ronell

Well-Known Member
Licensed User
Longtime User
i have a panel with 4 buttons and 1 imageview(circularimageview) when i try to change properties of all the buttons using this code
B4X:
For Each b As Button In panel
        b.Color = Colors.Transparent
    Next

this error is raised


B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **

** Activity (main) Resume **
click1
b1_click
main_b1_click (java line: 536)
java.lang.ClassCastException: com.pkmmte.circularimageview.CircularImageView cannot be cast to android.widget.Button
    at b4a.example.main._b1_click(main.java:536)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at de.donmanfred.IconButtonWrapper$1.onClick(IconButtonWrapper.java:73)
    at android.view.View.performClick(View.java:4465)
    at android.view.View$PerformClick.run(View.java:18788)
    at android.os.Handler.handleCallback(Handler.java:808)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:5292)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
    at dalvik.system.NativeStart.main(Native Method)

i guess the imageview is included when i iterate the views in the panel..
 

johndb

Active Member
Licensed User
Longtime User
Try this:
B4X:
Dim j As Int
For j = 0 To pnl.NumberOfViews-1
  Dim v As View = pnl.GetView(j)
  If v Is Button Then                   
     v.Color = Colors.Transparent
  End If
Next
 
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
thanks it works!

and also this code
B4X:
for each v as view in panel
  if v is button then
   v.color = color.black
  end if
next
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…