Android Question using layout files with customlistview's panels?

Discussion in 'Android Questions' started by leitor79, May 23, 2015.

  1. leitor79

    leitor79 Active Member Licensed User

    Hi,

    I'm loading a customlistview with manually configured panels, each with several addviews. It's kinda a mess to arrange them using top, left, width, height.

    I've been looking here and I've found references about users using layouts to load panels (questions asked and answered), "Panel.LoadLayout...", but what I can't find is how to access the loaded layout components.

    Let's say my "Layout1" has 2 labels, "Label1" and "Label2". How do I do something like this?

    Code:
    Panel.LoadLayout("Layout1")
    Panel.Label1="Hello"
    Panel.Label2="World"
    (I know it can't be done like this, it's an example of what I want to achieve)

    Regards!
     
  2. klaus

    klaus Expert Licensed User

    Code:
    Panel1.LoadLayout("Layout1")

    Dim lbl As Label
    lbl = Panel1.GetView(
    0)
    lbl.Text = 
    "Hello"
    lbl = Panel1.GetView(
    1)
    lbl.Text = 
    "World"
     
  3. leitor79

    leitor79 Active Member Licensed User

    Hi klaus,
    thank you for your answer.

    My panel has several labels and imageviews. And I don't like the idea of relying on an index; if I add or remove a view I have to fix all the indexes... and how I noew the indexes? They always corresponds to the order above the tree in the designer?

    Thank you very much!
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    There are all kinds of ways to access these views.

    One simple way is to declare global variables for these views. When you load the layout file the variables will reference the last set of views that were loaded.
    For example:
    Code:
    For i = 1 To 100
     Panel1.LoadLayout(...)
     Label1.Text = 
    "Text"
    Next
    If you want to access the views at a later stage you can declare a custom type:
    Code:
    Type ItemViews (lbl As Label, btn As Button)
    Code:
    For i = 1 To 100
     Panel1.LoadLayout(...)
     
    Dim iv As ItemViews
     iv.Initialize
     iv.lbl = Label1
     iv.btn = Button1
     Label1.Text = 
    "Text"
     Panel1.Tag = iv
    Next
    Later you can access the views:
    Code:
    Dim iv As ItemViews = Panel1.Tag
    iv.lbl.Text = 
    "sdfsdf"
     
    DonManfred, qsrtech and leitor79 like this.
  5. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Nice, I've never thought of storing anything other than a string for the Tag value. I'm sure I'll use this in new projects!
     
    DonManfred likes this.
  6. leitor79

    leitor79 Active Member Licensed User

    outstanding! thank you very much!
     
  7. qsrtech

    qsrtech Active Member Licensed User

    and just to confirm you use the original event and then find the sender within the itemviews?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    There are many ways to handle events. You can assign the same ItemViews object to the view that raises events (the button for example) and then get it from the Sender.
     
Loading...
  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