Android Question [solved]How to get the top distance value of the item in listview

Discussion in 'Android Questions' started by Maodge, Jul 6, 2018.

  1. Maodge

    Maodge Member Licensed User

    In my app, i want to dispaly somthing on the right of select item like the attached pic shows.
    so i must get the value of the select items' distance from the top.
    i find in B4A lib,and read listview doc of android.
    I have got no idea how to get that distance value.
    how to get the distance value?

    Attached Files:

  2. Syd Wright

    Syd Wright Active Member Licensed User

    I don't think this is possible with a regular listview. Even if you would be able to determine the top, then the result will not look nice due to lag: As soon as the user scrolls through the list, the picture (or other object) that you have placed on top of it will not move instantly. The top will continuously and rapidly have to be recalculated.
    Better to use a custom listview or better still: XCustomListview:
  3. Maodge

    Maodge Member Licensed User

    i find a function "getSelectedView" in android.
    getSelectedView added in API level 1
    public View getSelectedView ()
    View The view corresponding to the currently selected item, or null if nothing is selected

    Can this function be applied to listview?
    Last edited: Jul 7, 2018
  4. mangojack

    mangojack Well-Known Member Licensed User

    Another option would be to use xCustomListView. You could have a secondary view on the item layout for display which is set invisible.
    On list selection click you then show the hidden view.

    see attached sample .. I have included a variable to keep track of previously selected item to hide last displayed message.

    alternatively, you could just programmatically add the label / view to the list panel at selection.

    Attached Files:

    DonManfred likes this.
  5. Maodge

    Maodge Member Licensed User

    Thanks, @Syd Wright and @mangojack . thks for your advice and example :)
    i am going to change my code in this way.
  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