B4A Class NumericUpDown CustomView with Designer support

Hi Guys...

I'm not much of a Lib creator, but since B4A offers the possibility of compiling a class into a library, and me needing such a view, I created a very simple, yet fully functional Numeric Up and Down custom view.

As the name suggests, It's a simple incremental/decremental view witch can either be added by code or in the designer.

I share with you both the compiled library and the class. If you add functionality to the class, please do share...

Special Thanks to @Filippo for creating years ago the first version of this view, and to @klaus for making me see the forest beyond those dahm trees!

[EDIT] Ver. 1.15 - A small code error that prevented the view to be recognized by the designer is now hopefully fixed. Both Minus and Plus signs are now managed by canvas allowing for bigger and more readable buttons.

[EDIT] Ver. 1.5 - New "AddToParent" keyword to enable adding the view by code
 

Attachments

  • NumUpDown.zip
    5.6 KB · Views: 431
Last edited:

Cableguy

Expert
Licensed User
Longtime User
There's something strange happening in my lib/class.

In the original Project, all works fine and compiles flawlessly, BUT, when I try to use my LIB on another project, The designer does not recognize it as a custom view, when added as a class, it does recognize it.
But then, I get another problem... my compilation fails!

B4A version 4.30
Parsing code. 0.06
Compiling code. 0.33
Compiling layouts code. 0.05
Generating R file. 0.17
Compiling generated Java code. 6.50
Convert byte code - optimized dex. Error
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lb4a/example/numupdown;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
at com.android.dx.command.dexer.Main.processClass(Main.java:732)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access$300(Main.java:83)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)
at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
1 error; aborting
Optimized dexer failed. Switching to Standard dexer.

I just cannot understand it, please advise!!
 

klaus

Expert
Licensed User
Longtime User
I tried the Class. OK
Then I compiled it to a library. OK
Opened a new project, copied the code from the class project, checked the library and compiled it. OK.
When you test the library do you still have the class module in the project ?
If yes, you must remove it.
 

Cableguy

Expert
Licensed User
Longtime User
I have tried 2 ways:

add the view to the designer with the class - ok
then save the layout(after generating members)
remove the class, add the lib - the designer has changed the custom view type name but its still there, but nothing appears listed in the list, its blank... funny thing, compiled the project and works with no issues

adding the lib to a blank project, the view is not recognised by the designer
 
Last edited:

klaus

Expert
Licensed User
Longtime User
I did it the simple way, I copied the layout file from the other project.
Now tried it your way and get the same problem, I don't see it in the Designer.
The strange thing, with one of my own library I don't see it in the Designer, but with another one I see it.
Have not yet found why. Will look furthet tomorrow.
 

Cableguy

Expert
Licensed User
Longtime User
Thanks Klaus...It was driving me crazy not understanding were I was wrong... may be a glitch in the designer (?)
 

klaus

Expert
Licensed User
Longtime User
Hi Paulo.
I had a look at the problem to see what happens:

1) I made a new class test project, compiled it to a library.
Made a second project loading the library and adding the CustomView in the Designer worked.
So this shows that B4A version 4.30 works OK with a new project.

2) Then I made a new project for yor custom view, added a new class module, copied the whole code of your class into it and compiled it to a new library.
Made a new project, tryes to add the CustomView in the Designer, no success, it doesn't appear.
Then I saw in this class that the Public Sub DesignerCreateView(Base As Panel, lbl As Label, Props As Map) line was underlined with a warning.

3) Then I made once again a new project at the beginning only the skeleton and where I wrote a new Public Sub DesignerCreateView(Base As Panel, lbl As Label, Props As Map) not copying from the other project.
Compiled to a new library.
Made another new project to test the library and the CustomView appears ?!
Copied the rest of the code into the class, comiled the library and it works.

So, I don't understand why this happens.
I think that Erel should have a look at this.
Because I have also libraries where the CustomView appears in the Designer and other libraries where it doesn't appear.

Attached the two last working projects and the library files.
 

Attachments

  • NumericUpDownClassNew.zip
    13.5 KB · Views: 360
  • NumericUpDownLibNew.zip
    12.1 KB · Views: 326
  • NumericUpDown.jar
    3.7 KB · Views: 278
  • NumericUpDown.xml
    5.7 KB · Views: 313

Cableguy

Expert
Licensed User
Longtime User
Thaks for all your testing Klaus... I had seen the warning line about DesignerCreateView sub, but I thought it was due to the reason that this view is only used by the designer when loading the layout...
We'll see what @Erel hás to say and hoppefully it will be solved on next update
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
Then I saw in this class that the Public Sub DesignerCreateView(Base As Panel, lbl As Label, Props As Map) line was underlined with a warning.

Well, this got me thinking about this... I had declared my DesignerCreateView as Private, thus the warning...
Changing it to Public cleared the warning and the compiled lib seems to be recognized by the designer.
 

Cableguy

Expert
Licensed User
Longtime User
New Ver.1.5 published, see post #1
 
Top