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
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
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
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

hatzisn

Expert
Licensed User
Longtime User
I haven't used ListView since 1492, CustomListView is vastly better, but I think that's ONE of the MANY limitations of ListView, that you can't have items with different "styles".

Sorry, your application as Colombus cannot proceed because it violates timing rules set in devine last user agreement.

Next steps:
* Listen a lot of times the 1492 movie theme created by Vangelis
* Start by trying to command an air-full boat with which the children play at the beach
* Turn on your other side while you are lying at your bed.

😁😁😁😁😁
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
hot to get not same color?textcolor=black, than bgcolor=white
You CAN NOT define multiple colors for a SingleLineLayout!! All SingleLine-Items share the same layout, Colors.

Solution is
- NOT TO USE LISTVIEW (was already suggested to you!)
- To use CustomListView instead (was already suggested to you!)
 
Upvote 0
Top