B4A Library BadgeView - Add Badges to your views

DonManfred

Expert
Licensed User
ViewBadger
Version:
0.25

This is a wrapper for this java-library





ViewBadger
Version:
0.25
  • Badger
    Events:
    • onClick (value As Object)
    Methods:
    • Hide
    • Initialize (event As String, v As View, text As String, backgrouncColor As Int, AddClickListener As Boolean)
    • Show
    • Toggle
    • setPadding (left As Int, top As Int, right As Int, bottom As Int)
    Properties:
    • Position As Int [write only]
    • Tag As Object [write only]
    • Text As String [write only]

The Library is Donationware. You can try it out for free. If you then want to include the library in your project then you are forced to donate for this library. You can donate as much you want :)


The functionality of the "ClickListener" is successfully tested on the following Views:
Button, Panel, Label, ImageView, ToggleButton, RadioButton, ProgressBar and CheckBox

A ClickListener should NOT be set on the following Views (set last parameter of Initialize to FALSE here)
- Listviews
- Spinner
(maybe more but i have not tested them)
 

Attachments

Last edited:

DonManfred

Expert
Licensed User
Is it possible to change the color of the text?
In the next release you can
- Set the Textcolor
B4X:
badgeLbl.TextColor = Colors.Red
- Set the Textsize
B4X:
badgeLbl.TextSize = 24
- Set the fontface
B4X:
Dim MyFont As Typeface
MyFont = Typeface.LoadFromAssets("digi.ttf")
badgeLbl.Typeface = MyFont
See this example
 

Troberg

Well-Known Member
Licensed User
Badges? Badges! We don't need no stinking badges!

Sorry, but someone had to say it. :)

Looks very nice!

Some possible enhancements:

* Option to put them outside the "badged" view. Good for putting help tips.
* In combination with the above, option for "speech bubble pointer".

That way, you could have a speech bubble over, say, a button, saying "Click this to add songs". Somewhat like I did in the penultimate screenshot here (but I didn't do the speach bubble pointer): https://play.google.com/store/apps/details?id=com.troberg.jukedroid
 

DonManfred

Expert
Licensed User
Option to put them outside the "badged" view. Good for putting help tips.
It looks good on views which has an margin > 0. Buttons for example. Or ListView...




If there is no margin than the badge go outside of the visible area of this view....



But for buttons you can set the margin in the next version
B4X:
badgeBTN3.Margin = 0
or
B4X:
badgeBTN3.setMargin2(horizontal,vertical)
 

Troberg

Well-Known Member
Licensed User
Ah, I see, the badges live in the parent object, they are not simply attached to it. Then I understand whey they need to stay within it.

Anyway, still nice!
 

johndb

Active Member
Licensed User
I received the following error when setting "AddClickListener" to True in the Initialization using a Spinner as a view.
When "AddClickListener" is set to false then there is no error.

java.lang.RuntimeException: Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead
at android.widget.AdapterView.setOnClickListener(AdapterView.java:841)
at de.donmanfred.Badger.Initialize(Badger.java:44)
at com.sctech.ebase.main._activity_create(main.java:612)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at com.sctech.ebase.main.afterFirstLayout(main.java:98)
at com.sctech.ebase.main.access$100(main.java:16)
at com.sctech.ebase.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5579)
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:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead
 

DonManfred

Expert
Licensed User
I'm not using the AddClickListener event setting in my application so it's not a problem
If you set the last parameter of the initialize-command to true then the lib will try to add a clicklistener. Set the last parameter to false in this case. No listener will be created then.
i´ll try to change the lib so that we maybe can use a onitemclicklistener on spinners...
 

BarryW

Active Member
Licensed User
When i set the addclicklistener to true the view with this badge also trigger the badge click event. how to do only the badge will trigger the event not the view handling this badge... Tnx
 

DonManfred

Expert
Licensed User
When i set the addclicklistener to true the view with this badge also trigger the badge click event. how to do only the badge will trigger the event not the view handling this badge... Tnx
It cannot be handled alone.

The new object is an extension which is painted on the view itself. Setting the clicklistener allows you to get the click-event called when the badge is tapped.
 

Reids

Member
Licensed User
How to add badge on a tabhost or a listview item
I have FriendList.AddTwoLinesAndBitmap, I can put on Friendlist listview, but I cannot place badge on List Item itself because list item not a view :(
 

awakenblueheart

Member
Licensed User
I am using this badge. When the listbox item is selected, the badge should be change. But the badge become overlay on each other each time listbox item changed. How to solve this ya?
Tq.
 
Top