Android Question set font in View Array

yeroen

Member
Licensed User
Longtime User
I have this array of views:
Main.BtnGroupe(i).Editable=False
Main.BtnGroupe(i).Tag=i
Etcetera.
I want to set the font of all this views at Courier New.
How do i set the font? There is no Main.BtnGroupe(i).Font.
 

William Lancee

Well-Known Member
Licensed User
Longtime User
It is part of the Core. So nothing extra is needed.
How do you declare the Main.BtnGroupe(i) array?

If you declare the Array As View, you are right, there is no Typeface, since not all views have this.
The solution is to include the XUI library, which has B4XView which is a much smarter wrapper for Views.

B4X:
     'Private xui As XUI, include this in process globals

    Dim vArray() As B4XView = Array As B4XView(eb, Button1)
    For Each vw As B4XView In vArray
        vw.Font = xui.CreateFont(Typeface.MONOSPACE, 16)
    Next

Or.. If you already have lots of code with these arrays, use the new Inline casting feature:

B4X:
    Dim vArray() As View = Array As View(eb, Button1)
    For Each vw As View In vArray
        vw.As(B4XView).Font = xui.CreateFont(Typeface.MONOSPACE, 16)
    Next
 
Last edited:
Upvote 0

yeroen

Member
Licensed User
Longtime User
It is part of the Core. So nothing extra is needed.
How do you declare the Main.BtnGroupe(i) array?

If you declare the Array As View, you are right, there is no Typeface, since not all views have this.
The solution is to include the XUI library, which has B4XView which is a much smarter wrapper for Views.

B4X:
     'Private xui As XUI, include this in process globals

    Dim vArray() As B4XView = Array As B4XView(eb, Button1)
    For Each vw As B4XView In vArray
        vw.Font = xui.CreateFont(Typeface.MONOSPACE, 16)
    Next

Or.. If you already have lots of code with these arrays, use the new Inline casting feature:

B4X:
    Dim vArray() As View = Array As View(eb, Button1)
    For Each vw As View In vArray
        vw.As(B4XView).Font = xui.CreateFont(Typeface.MONOSPACE, 16)
    Next
Thank you. I still have a lot to learn about the structure and capabilities of B4X. I'm still doing too much on my own right now. Usually it works my way, but it's not efficient and invites mistakes.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
If your learning journey is like mine, you' be delighted by all the goodies that B4X has to offer.
There are many Forum members who won't hesitate to answer questions, even if they appear to be basic. I am one of them.

Do take advantage of the wonderful Booklets authored by @Klaus, I still learn from them. It is best to download the file below and unzip it to its own folder.

https://www.b4x.com/android/files/Booklets.zip
 
Upvote 0
Top