Android Question Adding parameters to source code

Mostafa86

Member
Licensed User
Hello,
I|m a beginner in Android application and need to add some features to the source code to show some extra measurements
I am going to add some parameters on the application.
My application measuring air pressure, temp. and .... now, I would like to add some other parameters too.
Is that enough to add lines under>
for example:
Private LabelPanelAcceleration As Label
Private LabelPanelAirHumidity As Label
Private LabelPanelAirPressure As Label
Private LabelPanelAirTemp As Label
Private LabelPanelBatteryLevel As Label
these are included in the source code
and some other codes in any other module and part of code, is it work only to add my lines under the defined parameters in source code?

Best regards.
 

KMatle

Expert
Licensed User
Longtime User
I don't understand your question. I assume you need to add views dynamically. I often use a Scrollview. Here you can add views scroll through it.

How to do that: See beginners guide, page 192 "adding views by code": https://www.b4x.com/android/forum/threads/b4a-beginners-guide.9578/

You can add the views with:

B4X:
Dim SV as ScrollView
SV.Initialize...
Activity.AddView(SV,......)

Dim MyLabel as Label
MyLabel.Initialize...
SV.Panel.AddView(MyLabel,......)

By the way: These are Code-Tags (looks better and it can be read much better)
 
Upvote 0

Mostafa86

Member
Licensed User
Thanks for the reply.
Here i send some screen shots,
the original source code has 8 parameters which are shown on the screen, now I'm going to add some new parameters.
I've followed the same as originals, Is that correct? the code is compiled and run but it does not come on the screen properly. It comes for a second and disappeared,
 

Attachments

  • Untitled11.png
    Untitled11.png
    92.8 KB · Views: 388
  • Untitled12.png
    Untitled12.png
    89.4 KB · Views: 371
Upvote 0

Mostafa86

Member
Licensed User
I do appreciate if you could give me a clue, because I really need to deal with this for some short time and will g back to my domain. If I want to learn Java I have to start from A.
I do appreciate if anyone can help i this case.
 
Upvote 0

Mostafa86

Member
Licensed User
thanks for the reply.
I'm a very beginner,:)
not really, I just followed the source code lines in every where in the code and added my parameters which I'm going to show them on the screen,
would you tell me how to do that?
Best regards.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
There are two ways to add objects to your project.

1. Add them in the Designer, where you can change the properties directly and see the effects. These objects are initialised during loading of the layout file.
2. Add objects with code, where you must initialise the objects yourself (Dimension object + initialise object + set properties. In that order)

Please read the beginners guide as detailed in post#2. This will help you.

From your post in #5, you have dimensioned the object but not initialised it and then tried to change a property. That will not work.
 
Upvote 0

Mostafa86

Member
Licensed User
Thanks you Mark.
would you please tell me where can I see the layout file for already source code objects which are available?
and where can I add this object initialization?
Best Regards.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
The layout file is called something like layout.bal and is found in your project/files directory. You can open it by using the designer option in the IDE to start the designer and then Open. Or you create a new layout file.

This is all detailed in sections 2 (My first program) and 3 (Second program) of the B4A beginners guide (sections as in Version 3.2).

I repeat "Please read the beginners guide as detailed in post#2. This will help you.".

If you have further questions regarding errors and coding problems then just ask. The forum is not really for asking for a step by step guide to programming and using B4A.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Here is a simple example (not tested).

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Button1 As Button
    Private Button2 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout")                'Layout.bal contains a single button called Button1
    Button2.Initialize("Button2")                'This button is not in the layout file
    Activity.AddView(Button2, 10dip,10dip,100dip,20dip)        'Add the button to the app screen   
   
    Button2.Text="Press me"                        'Add text to the button
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    'This is the event called when the button1 is clicked
End Sub

Sub Button2_Click
    'This is the event called when the button2 is clicked
End Sub
 
Upvote 0

Mostafa86

Member
Licensed User
Hello,
I have these two lines code:
it's a temperature converter, but I do not understand where these digits which have been highlighted come from?
May anyone help please.
Dim tempVal As Int
tempVal = Bit.ParseInt(data.SubString2(0,2), 16) * 256 + Bit.ParseInt(data.SubString2(2,4), 16)
tempVal = Bit.ParseInt(data.SubString2(0,4), 16)
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
SubString2(BeginIndex, EndIndex) - BeginIndex will be included but not EndIndex, returned is a string eg. "012345", SubString2(2,4) = "23"

** Index starts at 0! **

Method_636.png
Bit. ParseInt (Value As String, Radix As Int) As Int

Parses Value as an integer using the specified radix.
Radix - Should be between 2 to 36.
 
Upvote 0
Top