Domanda

I have tree of views, looking something like this.

-- parent view top
  -- parent view mid 
  -- parent view mid
    -- parent view low
    -- parent view low
      -- child 1
      -- child 2
      -- child 3

I want to check from the child level the id of the top parent view to apply some logic there, based on some TouchEvents in child. Do you know how can I design the recursive function which will allow me to iterate to the top?

I was able with the usage of getParent() method to get to desired Parent, but this solution is not flexible enough for me at this moment.

È stato utile?

Soluzione

A recursive function from child to parent can be done in this way.

public void doSomething(View view) {
    // 
    // do something here
    //

    if(view.getParent() != null) 
    {
        doSomething(view.getParent());
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top