Android Question Combobox typeface change and adding items

harinder

Active Member
Licensed User
Longtime User
Hi..
I was looking to add a string of days as items to a combobox and also change typeface:

B4X:
    Dim cs As CSBuilder
    Dim myFont As Typeface = Typeface.CreateNew(Typeface.LoadFromAssets("myfont.ttf"), Typeface.STYLE_BOLD)
    Dim s() As String =Array  ("-","7","10","14","30","60","90","180","365")
    For i=0 To s.Length -1
       spnrmks.cmbBox.Addall(Array (cs.Initialize.Typeface(myFont).Append(i).PopAll))
    Next

But I am getting error:
java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.String[]

Halp..Thnx
 

mangojack

Expert
Licensed User
Longtime User
Change to
B4X:
Dim s() As String = Array As String("-","7","10","14","30","60","90","180","365")

Strangely, compiling without error , then removing "As String" it did not error again in subsequent compiles (debug mode)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
For i=0 To s.Length -1 spnrmks.cmbBox.Addall(Array (cs.Initialize.Typeface(myFont).Append(i).PopAll)) Next
this will add i, the loop variable.

Additional: If you want to use addall you need to create a list with all items first. then add the list with addall.

Shouldn´t it be
B4X:
For i=0 To s.Length -1
   spnrmks.cmbBox.Add(cs.Initialize.Typeface(myFont).Append(s(i)).PopAll)
Next
to add the items in the Loop?
 
Last edited:
Upvote 0

harinder

Active Member
Licensed User
Longtime User
Adding items to a list and then changing typeface works fine as follows:

B4X:
    Dim s As List
    s.Initialize
    s.AddAll(Array As String ("-","7","10","14","30","60","90","180","365") )
    For Each day As String In s
    spndays.cmbBox.Addall(Array(cs.Initialize.Typeface(myFont).Append(day).PopAll))
    Next

Erel... I can use spndays.setitems(s) to add items to the combobox. But how do I change the typeface in this code line? Thnx
 
Upvote 0

harinder

Active Member
Licensed User
Longtime User
Hi Erel..thank you
Is it possible to change typeface without using the second list(as in your code) and the internal cmbbox(as in my code)?
 
Upvote 0
Top