0

Is there a way to create an array containing actual instances of views. For example, if I have one LinearLayout called Container that has within it 3 other LinearLayouts with the same Tag attribute and I wanted to get a list containing all 3 LinearLayouts so I can loop through and handle each.

Tried:

LinearLayout[] layouts = (LinearLayout[]) Container.FindViewWithTag(tag);

and

List<LinearLayout> layouts = (List<LinearLayout>) Container.FindViewWithTag(tag);

and

foreach(LinearLayout layouts in Container.FindViewWithTag(tag))

None of these have been acceptable to Android so far. Another acceptable way to handle my situation would be to just be able to assign each LinearLayout a Parent. But I haven't found a way to programatically set a view's parent, only how to get a view's parent.

jmease
  • 2,507
  • 5
  • 49
  • 89

1 Answers1

1

What I have understood from your question that you want the child of Linear Layout. Yes, you can get the child of linear layout by container.getChild(index)

for(int i=0;i<container.getChildCount();i++){
       View child=container.getChildAt(i);
       //your processing....
  }
SALMAN
  • 2,031
  • 1
  • 20
  • 18
  • 1
    Sorry. Please allow me to try to clarify. I have my containing LinearLayout to which I am appending a number of other LinearLayouts. It is these new layouts for which I am trying to create some sort of Parent/Child relationship between. Hence the shared tags which is my attempt at "grouping" the layouts with a parent. Originally tried to use an ExpandableListView which makes way more sense and would make this a ton easier, but I spent too many hours banging my head against the wall with using clickable views that I abandoned that and just tried creating my own "ExpandableListView". – jmease Jul 03 '12 at 18:29
  • Why dont you use default widget of ExpandlableListView ? Are you getting a problem of click in Default control of ExpandlableListView? – SALMAN Jul 03 '12 at 18:32
  • Like I said, I started with ExpandableListView. But I had CheckBoxes, AutoCompleteTextViews and Buttons in there and was having issue after issue with it. – jmease Jul 03 '12 at 18:33
  • I can help you to get rid of those problems which you are facing in Expandable ListView, it is good practice to use default controls. – SALMAN Jul 03 '12 at 18:34
  • Please see http://stackoverflow.com/questions/11318920/clickable-views-in-customer-expandablelistview – jmease Jul 03 '12 at 20:48