Android Question how to get listview1 itemcolor?

xiaoyao

Active Member
Licensed User
Longtime User
can't run
B4X:
Sub GetSystemTextColor As Int
    Dim co As Int

    Dim typedValue As JavaObject
    typedValue.InitializeNewInstance("android.util.TypedValue", Null)
    
    Dim theme As JavaObject = Activity
    theme = theme.RunMethod("getTheme", Null)
    Dim value As Boolean = theme.RunMethod("resolveAttribute", Array As Object(android.R.attr.textColorPrimary, typedValue, True))
    
    If value Then
        Return typedValue.GetField("data")
    Else
        Return Colors.Black '
    End If
    
End Sub
 

teddybear

Well-Known Member
Licensed User
1. As Erel suggested, why don't you use customlistview instead of listview?
2. The code looks like it was generated by AI. it seems to only retrieve the theme's textColorPrimary, and has nothing to do with the listview.
3. If you would like to get the textColorPrimary, you need to initialize the object android.R.attr instead of passing a literal "android.R.attr.textColorPrimary" as a parameter.
4. You'd better post full error log. I guess it's not "can't run" but "can't compile"
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Without knowing what you are exactly doing it's not easy to answer.
If you are adding simple items like
B4X:
ListView1.AddSingleLine("HELLO")
then you can do this to get the text color
B4X:
Dim Label1 As B4XView = ListView1.SingleLineLayout.Label
Log(Label1.TextColor)    'Color of the Text
Log(Label.Color)        'Color of the Item
supposing that ALL the items have the same color.
 
Upvote 0

xiaoyao

Active Member
Licensed User
Longtime User
ListView1.AddSingleLine("abc")
'ListView1.a
Dim Label1 As B4XView = ListView1.SingleLineLayout.Label

Log(Label1.TextColor) 'Color of the Text
xui.MsgboxAsync(Label1.Color & "," & Label1.TextSize,"")
more times,textcolor=0(white)
i only want set listview1 bgcolor to yellow or black

hot to get not same color?textcolor=black, than bgcolor=white
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…