Android Question CustomListView change panel(list) background color when clicked

Discussion in 'Android Questions' started by phukol, Jul 13, 2015.

  1. phukol

    phukol Active Member Licensed User

    Hi guys, just want to ask how can i change the background color of my CustomListView when i click or press one of the list. Currently, its constantly giving me the orange color.

    Attached Files:

  2. eurojam

    eurojam Well-Known Member Licensed User

    you can do something similar to this, it is just an example, not tested;
    first you add some Panels to your customlistview, like
    For i = 1 To 10
    Dim p As Panel
    50dip"Item #" & i)
    then you define the panel_click sub like
    Sub clv_panel_Click
    Dim p As Panel
        p = 
        p.Color = 
    End Sub
    that's it, more or less
    kemanlam, DonManfred and mangojack like this.
  3. phukol

    phukol Active Member Licensed User

    Thank you that will work, however, when you click on the panel, they will turn to green but if ever you select and click another panel, it will also turn to green. Also the click event of customlist view will be disabled. Im thinking that it would be better if we change the code in customlistview to change the actual click event for it.

    Attached Files:

  4. phukol

    phukol Active Member Licensed User

    I looked around and found out that i need to change this:
    idPressed = r.GetStaticField("android.R$drawable", "list_selector_background")

    "list_selector_background" to "list_pressed_holo_dark"

    however i need to use the android resources library to access list_pressed_holo_dark? can anyone point me how i can do this?
  5. phukol

    phukol Active Member Licensed User

    For anyone having the same issue kindly use NinePatch Drawabales tutorial. What i did is make a sub which returns a drawable like this
    Public Sub SetNinePatchDrawable( ImageName As StringAs BitmapDrawable
    Dim r As Reflector
    Dim package As String
    Dim id As Int
       package = r.GetStaticField(
    id = r.GetStaticField(package & ".R$drawable", ImageName)
       r.Target = r.GetContext
       r.Target = r.RunMethod(
    Return  r.RunMethod2("getDrawable"id"")
    End Sub
    Then i made use of a png background placed inside Objects > res > drawable. Set it to read only and just call it's file like this
    pressedDrawable = Utils.SetNinePatchDrawable("list_selector_pressed_holo_dark")
    And problem fixed.
    lazreg likes this.
  6. imbault

    imbault Well-Known Member Licensed User

    @phukol , can you explain how you modify:
    idPressed = r.GetStaticField("android.R$drawable""list_selector_background")
    To something else, in order to get another backcolor, when an item of the CustomListView is clicked

    Thanks a lot
    lazreg likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice