Android Tutorial Collecting tips - Beginners wanted!

Status
Not open for further replies.

alfcen

Well-Known Member
Licensed User
Longtime User
Tip for creating androidy menu and listview icons

No need for spending hours on creating your icon graphics or looking for copyrighted free stuff among tons of suspicious ads.

Windows comes with font sets, such as Windings and Webdings which include abundant symbols.

In PhotoShop, PaintShop Pro or similar create a new transparent layer sized 48 x 48 pixels, which is just right for the menu. Tablets may require higher resolutions.

Select either Webdings or Windings font and place a symbol using the text tool and set the color to dark gray, such as R 140 G 140 B 140. If you like shadows, etc., try and play which layer styles. Satin and Bevel are good choices.

Save your work as PNG.

The minimum size for ListView images for phones is 64 x 64, again assuming that tablets may ask for more.

Examples:
http://www.requio.com/b4aforum/icons3.png
http://www.requio.com/b4aforum/icons5.png
 

Brad

Active Member
Licensed User
Longtime User
Here's one way in implementing a max length for EditText views.
Sample to limit the length to 40 characters.
B4X:
Sub EditText1_TextChanged (Old As String, New As String)
If New.Length > 39 Then
   EditText1.Text = Old
   EditText1.SelectionStart = Old.Length
' insert code to trigger phone vibrate or display toastmessage
End If
End Sub
 
Last edited:

Brad

Active Member
Licensed User
Longtime User

I use GIMP which is similar to Photoshop and is free.
 

warwound

Expert
Licensed User
Longtime User
Set TabHost tab height

Hi all.

Here's a way to change the height of the tabs in a TabHost.

Many seem to find the default tab height to take up too much of the screen so now you can reduce the tab height to suit.

Here's my code:

B4X:
'   Set tab height example activity
Sub Process_Globals
End Sub

Sub Globals
   Dim EditText1 As EditText
   Dim Reflector1 As Reflector
   Dim TabHost1 As TabHost
   Dim Button1 As Button
   Dim Label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("LayoutMain")
   
   Dim i As Int
   For i=0 To 3
      TabHost1.AddTab("Tab#"&i, "TabContent")
      EditText1.Tag=i
      Label1.Text="This is Tab#"&i
   Next
   
   Dim TabWidget As Object
   Dim TabIndicator As View
   Dim TabIndex, TabCount As Int
   
   '   the Java to execute is:
   '   TabHost1.getTabWidget().getChildAt(TabIndex).getLayoutParams().height = 30;
   
   Reflector1.Target=TabHost1
   TabWidget=Reflector1.RunMethod("getTabWidget")
   Reflector1.Target=TabWidget
   TabCount=Reflector1.RunMethod("getTabCount")
   For TabIndex=0 To TabCount-1
      TabIndicator=Reflector1.RunMethod2("getChildAt", TabIndex, "java.lang.int")
      TabIndicator.Height=30
   Next
   '   the (global) Reflector1 Target object will be TabHost1's TabWidget object when this Sub exits 
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub EditText1_EnterPressed
   Dim Index As String
   Dim TabIndicator As View
   Dim EditText2 As EditText
   Dim Value As Int
   EditText2=Sender
   If EditText2.Text<>"" Then
      Index=EditText2.Tag
      Value=EditText2.Text
      TabIndicator=Reflector1.RunMethod2("getChildAt", Index, "java.lang.int")
      TabIndicator.Height=Value
   End If
End Sub

Sub TabHost1_SetVisibility(Visible As Boolean)
   Dim TabIndex, TabCount, TabHeight As Int
   Dim TabIndicator As View
   If Visible Then
      TabHeight=30
   Else
      TabHeight=0
   End If
   TabCount=Reflector1.RunMethod("getTabCount")
   For TabIndex=0 To TabCount-1
      TabIndicator=Reflector1.RunMethod2("getChildAt", TabIndex, "java.lang.int")
      TabIndicator.Height=TabHeight
   Next
End Sub

Sub Button1_Click
   Dim Button2 As Button
   Dim Text As String
   Button2=Sender
   Text=Button2.Text
   If Text="Hide tabs" Then
      TabHost1_SetVisibility(False)
      Button2.Text="Show tabs"
   Else
      TabHost1_SetVisibility(True)
      Button2.Text="Hide tabs"
   End If
End Sub

On an AVD with a 320x480 resolution screen (density 160dpi) a tab height of 30 pixels is about the minimum i'd consider using.
Looking at the Log i see the AVD's default tab height is 64 pixels so if you're not using tabs with icons there is plenty of screen estate to reclaim from the TabHost.

The code also includes a Sub which can show or hide the tabs - hiding the tabs by setting their height to zero pixels.

Martin.

[edit]I have now made this into a code module and a library - for info see this thread: http://www.b4x.com/forum/additional-libraries-official-updates/11056-tabhostextras.html#post61757[/edit]
 

Attachments

  • TabHeight.zip
    6.7 KB · Views: 349
Last edited:

VIC20

New Member
IDE Tip

Hi and thank you for a nice product!
Coming from the VB6 IDE i really felt at home from the start.

One nice feature in VB is that you can quickly jump to a sub in the code by standing on the call and press SHIFT+F2.
Then you can jump back by pressing CTRL+SHIFT+F2.

This feature has saved me countless hours of development time since i didn't have to search and search to find the sub.

Sub DoStuff
DoIt '(Standing on "DoIt", and pressing SHIFT+F2....)
End Sub

'Code,Code,Code,Code......

Sub DoIt '(Ends up here in "DoIt". CTRL+SHIFT+F2 jumps back)
X=Y
End Sub
 

Kevin

Well-Known Member
Licensed User
Longtime User
Locating references to variables or unused variables

The first time I noticed this I thought it was a graphical glitch, then sometime later realized the meaning behind it. Today I just realized some of its usefulness! This may be old news to some (I think some code editors have done this for a while) but this was new to me:

If you double-click on or highlight a variable, such the word HttpClient1 in the code below......

B4X:
Dim HttpClient1 As HttpClient

...... the code window will show light blue lines in the code window's scroll bar area off to the right. These lines show other portions of your code that reference that same variable.


I am finding two handy uses for this:


1) Obviously it is a quick way to jump to a section of your code that references this variable.

2) When cleaning up your project to remove dead code and variable declarations, this is a quick way to see if a variable you have Dim'd is not used by your project. If you don't see any light blue lines in the scroll bar area, then you can safely remove the Dim statement for that variable.


As for #2, I mistakenly was thinking that Tools>Clean Project would list unused variables and such, but it doesn't. Perhaps some kind of tool can be added to scan for such unused things, such as unused variables, subs that are never called, etc?
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User

Are you saying that B4A does this? If so, it doesn't work for me. (By "standing on", I assume you mean place the cursor on the call.)
 

Kevin

Well-Known Member
Licensed User
Longtime User
Are you saying that B4A does this? If so, it doesn't work for me. (By "standing on", I assume you mean place the cursor on the call.)


I'm reading that more as a request, but I could be mistaken.

Not a bad idea though.
 

JonPM

Well-Known Member
Licensed User
Longtime User
I am a beginner and one piece of advice I would give is that when u first start a project take the time to get your layouts/variants exactly the way you want them before getting too far into the project. I am currently working on my first b4a project and didn't do so. Now I have 20+ layouts with 20+ activities that I need to go back and modify.

Sent from my DROIDX
 

rayzrocket

Member
Licensed User
Longtime User
still wet behind the ears newbie

Great job B4A team!
I request that you make the 'my first program' a bit more complete. I had no idea what was being compiled(file sets), where it was put(default folder or user specified), and how to get the program into my phone(usb cable/bluetooth/market) and running(where it is in the phone and install).

I have figured it out, but I will let someone better than I explain it.

:sign0104:
 

TomDuncan

Active Member
Licensed User
Longtime User
Getting Date from Sql database

Hi,
The date from my SQL database comes in as yyyy/MM/dd
Here is asimple way to display in the required format.

Dim TheDate As Long
DateTime.DateFormat = "yyyy-MM-dd"
TheDate= DateTime.DateParse(Cursor1.GetString("Dob"))
DateTime.DateFormat = "dd/MM/yyyy"
Text= DateTime.Date(TheDate)

Tom
 

Roeschti

Member
Licensed User
Longtime User
Little hint

I found a nice "feature" for probing around with diffrent designs / views. If you want to see how it looks real you have to publish the application to the emulator or an real device. I dont like that, cause the emulator is extremly slow. If you make a lot of smaller changes and always have to wait for the emulator...it's a pain.

But...if you use B4A Brigde on a device you can connect the Designer to the Emulator and IDE to the real device simultaneously. So you can look in the Emulator and the device at the same time to see the differences of your changes.
 

CarlM

Member
Licensed User
Longtime User
Confirming File Removal

As a complete noob I 'removed' a wrong module file from the code modules list in the IDE.

Maybe the confirmation to delete file dialog could state the name of the module you are about to delete forever?
eg:
Menu: Project > Remove Module >

Messagebox "Do you want to remove this module?"

could read:
"Do you want to remove module <<modulename>>?"

:signOops:
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…