Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 22nd, 2012  |  syntax: None  |  size: 1.25 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. find all spinners that match a tag
  2. LinearLayout ll = //Your Layout this can be any Linear or Relative layout
  3.                      //in which you added your spinners at runtime ;
  4.  
  5.     int count = ll.getChildCount();
  6.     for(int i =0;i<count;i++)
  7.     {
  8.         View v = ll.getChildAt(i);
  9.         if(v instanceof Spinner)
  10.         {
  11.             // you got the spinner
  12.             Spinner s = (Spinner) v;
  13.             Log.i("Item selected",s.getSelectedItem().toString());
  14.         }
  15.     }
  16.        
  17. Vector spinners = new Vector ():
  18.  
  19. private void treverseGroup(ViewGroup vg)
  20. {
  21.     final int count = vg.getChildCount();
  22.     for (int i = 0; i < count; ++i)
  23.     {
  24.         if (vg.getChildAt(i) instanceof Spinner)
  25.         {
  26.  
  27.           spinners.add(vg.getChildAt(i));
  28.         }
  29.         else if (vg.getChildAt(i) instanceof ViewGroup)
  30.             recurseGroup((ViewGroup) gp.getChildAt(i));
  31.     }
  32.  
  33. }
  34.        
  35. private ArrayList<Spinner> getSpinners(ViewGroup root, Object matchingTag) {
  36.     ArrayList<?> list = root.getTouchables();
  37.  
  38.     Iterator<?> it = list.iterator();
  39.     while (it.hasNext()) {
  40.         View view = (View) it.next();
  41.         if (!(view instanceof Spinner && view.getTag().equals(matchingTag))) {
  42.             it.remove();
  43.         }
  44.     }
  45.  
  46.     return (ArrayList<Spinner>) list;
  47. }