0% found this document useful (0 votes)
284 views5 pages

B4a Brief

This document provides instructions for creating a simple guessing game app using B4A. It includes: 1. Storing a random number and comparing the user's input to determine if it is higher or lower than the stored number. 2. Adding a button and text edit field to accept the user's guess. 3. Displaying a toast message indicating whether the guess is higher, lower, or correct. It then provides an example of creating a list view with customizable properties like text size, color, and background color when selected or scrolling. The list view title is also updated based on the item clicked.

Uploaded by

gsvade
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
284 views5 pages

B4a Brief

This document provides instructions for creating a simple guessing game app using B4A. It includes: 1. Storing a random number and comparing the user's input to determine if it is higher or lower than the stored number. 2. Adding a button and text edit field to accept the user's guess. 3. Displaying a toast message indicating whether the guess is higher, lower, or correct. It then provides an example of creating a list view with customizable properties like text size, color, and background color when selected or scrolling. The list view title is also updated based on the item clicked.

Uploaded by

gsvade
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Creating B4A program Invoke B4A Tool. File >> New Save as Hello.

b4a Add code


Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("Layout1") Log("Hello World") Msgbox("Hello World","This is the Title") End Sub

Press F5 to compile . Copy hello.dbk to c:\user\Vijay\youwave Start youwave and click B4A Example

Notice MsgBox Displayed caption=Hello World along with Title=This is the Title

Now Open Designer AddView>>Label =Label1 Rtclk Label1 >>Generate>>Label1 as Label This will add code in sub Globals section Dim Label1 as Label

Now Save Designer Layout as Main Add following code Sub Activity_Create() Activity.LoadLayout(Main) Label1.Text = Hello World End Sub Again Rtclk Label1>>Generate>>click This will generate templae Label1_Click. Add the code Sub Label1_Click Label1.Text = Who Clicked Me End Sub Compile and Run You See a Label Hello World is displayed If you click on the Label , it will turn to Who clicked Me

===================================x============================================= Ex: Guess My Number Computer Stores a number on startup. You has to enter a Guess number in TextEdit and Click the Button. Computer compares the User Entry with Stored Guess and Display message accordingly.

Add a Button and TextEdit

Add Click Event to Button Add code:


Code:

Sub Globals Dim MyNumber As Int Dim EditText1 As EditText End Sub Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("Main") 'Load the layout file Main.bal. MyNumber = Rnd(1, 100) 'Choose a random number between 1 to 99 End Sub Sub Button1_Click If EditText1.Text > MyNumber Then ToastMessageShow("My number is smaller.", False) Else If EditText1.Text < MyNumber Then ToastMessageShow("My number is larger.", False) Else ToastMessageShow("Well done.", True) End If EditText1.SelectAll End Sub

=================== xxx=============================== Ex: ListView Create List with 20 Items List Item with textcolour=Blue, List background=Gray (Normal) Blue (Whenclicked) Black (When Scrolled) List Title Update to ID of clicked cell
Sub Globals Dim ListView1 As ListView End Sub Sub Activity_Create(FirstTime As Boolean) 'Load layout file Main.bal created with B4A designer Activity.LoadLayout("Main") 'Initialize List and set event name=ListView1 ListView1.Initialize("ListView1") 'Set Properties of ListItems such as Height, Color, Alignment ListView1.SingleLineLayout.ItemHeight=100dip 'Note use of dip unit which causes autoscaling ListView1.SingleLineLayout.Label.TextSize = 40'Note dip unit is notused here since text size is already measured in scaled unit ListView1.SingleLineLayout.Label.TextColor = Colors.Blue ListView1.SingleLineLayout.Label.Gravity= Gravity.CENTER ListView1.ScrollingBackgroundColor= Colors.Black ListView1.Color=Colors.Gray ListView1.FastScrollEnabled=True 'Enable this if you have many item to scroll 'Add Items to the List For i = 1 To 20 ListView1.AddSingleLine("item #" & i) Next

'Disp List on Activity. Note use of percent unit for width and height Activity.AddView(ListView1,0,0,100%x,100%y) End Sub Sub ListView1_ItemClick(Position As Int, Value As Object) Activity.Title = Value End Sub

We can set background to gradient while scrolling with this code


Dim GD As GradientDrawable GD.Initialize("TR_BL", Array As Int(Colors.Gray, Colors.LightGray)) Activity.Background = GD

There are three types of ListView Items 1. singleLineLayout 2. TwoLinesLayout 3. TwoLinesAndBitmap

Dim Bitmap1 As Bitmap Bitmap1.Initialize(File.DirAssets, "button.gif")button.gip must be placed in Projects sub Directory named Files For i = 1 To 300 ListView1.AddSingleLine("Item #" & i) ListView1.AddTwoLines("Item #" & i, "This is the second line.") ListView1.AddTwoLinesAndBitmap("Item #" & i, "This is the second line.", Bitmap1) Next

You might also like