Android Tutorial B4A Beginners Guide

klaus

Expert
Licensed User
Do you belive this thing is doable?
Yes !
There alraedy do exist some example programs doing what you want to do, perhahps not the synchronisation with the PC.
The example I am preparing for the Beginner's guide will almost do it (without the synchronisation).

Bestr regards.
 

AscySoft

Active Member
Licensed User
It's great...

Yes !
The example I am preparing for the Beginner's guide will almost do it
It is something super! I hardly wait to see a well-documented example, but until then I still have a lot to learn. Thanks a lot!:sign0060:
 

RandomCoder

Well-Known Member
Licensed User
Great Manual

Thank you Klaus for creating such a detailed guide along with so many screen shots and sample source code, it must have taken a considerable amount of your time. This really should be part of the B4A installation and made readily available from the help menu as it is invaluable to anyone that is just starting out.
I’ve been using B4PPC for almost 5 years and whilst B4A looks familiar it is also strangely different. One of the things I liked with B4PPC was how easy it was to get help on specific keywords and this often contained an example usage. B4A just feels like it is geared towards a slightly more advanced programmer, for example in my first app I require a couple of ImageButtons but the keyword help for Button suggests two members relating to the button background....
Background As android.graphics.drawable.Drawable and SetBackgroundImage(Bitmap As android.graphics.Bitmap)
It also suggests that if changing the Button background then StateListDrawable is preferable as it offers two different backgrounds, one for default and one for when pressed.

I’ve had a little play and got an image to work using....
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("frmLoneWorker")
   bmpHand.Initialize( File.DirAssets , "Hand.png" )
   btnAcknowledge.SetBackgroundImage( bmpHand )
End Sub
But I still had no idea what the Background member was expecting to be given because android.graphics.drawable.Drawable might as well be written in Swahili for all the help it is in telling me what syntax to use.
Thankfully the Forum is still an excellent place to find the answers and in this post http://www.basic4ppc.com/forum/41047-post13.html (also by you) it is clearly explained.

I also find it strange that what used to be a Form is now an Activity but whereas each Form had to have a unique identifier this does not appear to be so with Activities? I see from the ThreeActivityExample that when an activity is called all references to Activity.(dot) must relate to the Activity that has the focus and if I’ve interpreted the manual correctly any previous Activities although still present in the background could potentially get removed to free up memory. Have I understood correctly, as this is in direct contrast to B4PPC where the main Form could open several other Forms but if the main Form was closed then all other Forms would close with it?
I noticed a similar issue on Page 101 of the manual, relating to Casting. In the second example all the Buttons are named Btn....
B4X:
Sub Activity_Create(FirstTime As Boolean)
For i = 0 To 9
   Dim btn As Button
   btn.Initialize("btn")
   activity.AddView(btn,10dip,10dip+60dip*i,200dip,50dip)
Next
End Sub
I would have expected this not to work because each Button is not uniquely identified and yet it does, but how?
Anyway, sorry for the long winded reply and a very BIG THANK YOU for the great work you have put into this manual. I’ll now get stuck into using B4A and see what new problems I find.

W.R.T typo’s, the manual is exceptionally well written but I have found a couple of errors you may wish to correct...
P.85 Para heading “Name” – “lblResult”, “lbl” for Editext and “Result” for purpose.
P.99 Both examples to access all items in an array – For i = on all three nested statements instead of i then j then k.
P.129 Second line – declared in the directly in the list

Kind regards,
RandomCoder
 

klaus

Expert
Licensed User
Hi RandomCoder,
Welcome in the Android 'world' and thank you for your nice comments.
I am glad that you find it usefull.

At a first look, B4PPC and B4A seem beeing quite similar.
Yes they are, the basic language is almost the same, there are just a few differences.
No they are not, because the operating system is not the same there are big differences for all the user interace stuff.

Forms don't exist like in WM.
Android uses Activities, and the most important is to understand their life cycle. There is only one active Activity at the same time.

Objects are called Views.
Coming to your question about the buttons having the same name, the Android OS doesn't know the names of the views but knows an internal handler. B4Android does it for you when all names are different.
Different Views can have the same event handling routine, and to know what view raised the event we use the Sender keyword like in B4PPC. The difference in B4A is that Sender doesn't return the name of the View but the view as an object. The only way, in B4A, to know what View has raised the event is the Tag parameter. The example on page 101 doesn't show the Tag parameter principle. Have a look at the code in the Second program there is also a panel with buttons, there they are added in the Designer but they could have been added by code with the same name. In the example they have different names but the important parameter is their Tag parameter. The event handling is explained on pages 39-40.
There is no difference between a Button and an ImageButton like in B4PPC. An Android Button can have several background settings, as you already saw. It is relatively easy to define these parameters in the Designer, but in the code it's somewhat more complicated. That's why I didn't add this in the Beginner's Guide.

Thank you for the typo report, they are amended in my original file.
An update of the Beginner's Guide will come quite soon.

Best regards.
 

RandomCoder

Well-Known Member
Licensed User
Coming to your question about the buttons having the same name, the Android OS doesn't know the names of the views but knows an internal handler. B4Android does it for you
Thanks for the explanation.
I feel it is important to understand the fundamentals before getting to stuck into the programming :sign0098:

Regards,
RandomCoder
 

klaus

Expert
Licensed User
A new update of the Beginner's Guide is available, version 1.2.
Added chapters:
- Modules
- Example Programs
- ScrollView example
- Database example
- Basic Language
- String manipulations
- Timers
- Graphics

- Chapter numbers on top of each page.

The source codes of the example programs are included.

As usual, suggestions, wishes, typo and bug reports are welcome.

Best regards.
 

nfordbscndrd

Well-Known Member
Licensed User
Man, how I wish this had been around when I started using B4A back in the old days (you know -- January). It would have saved me countless hours/days.

Great job!
 

AscySoft

Active Member
Licensed User
A new update of the Beginner's Guide is available, version 1.2.
Added chapters:
- Modules
- Example Programs
- ScrollView example
- Database example
- Basic Language
- String manipulations
- Timers
- Graphics
Best regards.
:sign0188: :sign0098:

Thank you. As expected, U did a professional job.
:wav:
 

Brad

Active Member
Licensed User
Edit: Placed in wrong thread...moved to Tips
 
Last edited:

Hubert Brandel

Active Member
Licensed User
Hi,

thanks for this excellent work, easy to understand and exactly what a Basic4Android newby (like me) needs.

Here I found one thing you might want to change by time ...
In the first Example (MyFirstProgram) on Page 27 you define the "Number" Vars as double, but the program just need INT.
On my example the double Vars looks like 5.0 instead of 5 like your screenshot.
Thirst I thought I have made a mistake in the code, than if there is a formating style in the lables, but then I changed the line 19:

Old: Dim Number1, Number2 As Double
New: Dim Number1, Number2 As Int

And my program behave like yours. And now to the second one :sign0060:

Regards,
Hubert
 
Last edited:

klaus

Expert
Licensed User
Hi Hubert,
Thank you for the bug report.
It will be fixed in version 1.4 .

Best regards.
 

Hubert Brandel

Active Member
Licensed User
Hi Klaus,

I think I can offer another one ;-)

I have a Samsung Galaxy S+ with 480x800-240. In the examples with the menus (UserInterfaceButtonToolbox.b4a, UserInterfaceMenu.b4a, UserInterfaceTabHost.b4a and ThreeActivityExample.b4a) the height of the tabpage is calculated like this:

B4X:
Sub Activity_Create(FirstTime As Boolean)
   ...
   Activity.LoadLayout("Main")    ' Loads "Main" layout file
   ...   
   PanelHeight = Activity.Height - pnlToolbox.Height - 5dip

   pnlPage1.Initialize("")       ' Initializes pnlPage1
   pnlPage1.LoadLayout("Page1")   ' Loads "Page1" layout file
   Activity.AddView(pnlPage1,0,0,100%x,PanelHeight)
the heigth and the TOP of pnlToolbox is defined in the designer.
But my display is higher and so the buttons will be under the TabPanels.

I think there TOP should be calculated too.

B4X:
Sub Activity_Create(FirstTime As Boolean)
   ...
   Activity.LoadLayout("Main")    ' Loads "Main" layout file
   ...   
   PanelHeight = Activity.Height - pnlToolbox.Height - 5dip
   pnlToolbox.Top = Activity.Height - pnlToolbox.Height

   pnlPage1.Initialize("")       ' Initializes pnlPage1
   pnlPage1.LoadLayout("Page1")   ' Loads "Page1" layout file
   Activity.AddView(pnlPage1,0,0,100%x,PanelHeight)
In this way I can see und push them.

Regards,
Hubert
 
Last edited:

klaus

Expert
Licensed User
Hi Hubert,
Thank you for reporting.
You are right, the top property of the ToolBox must also be calculated.
UserInterfaceButtonToolbox.b4a and ThreeActivityExample.b4a will be updated in the next version.
UserInterfaceMenu.b4a and UserInterfaceTabHost.b4a no need.

Best regards.
 

zouriteman

Member
Licensed User
DIP or DIPP

KLAUS ,
in the above post #58 from HUBERT BRADEL , he write
5dipp

it's an error , or a new variant of 5dip ?? :BangHead:
 
Top