Check if a View contains another View

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Check if a View contains another View

Postby xspotlivin » Sat Apr 18, 2009 10:56 pm

Is there a way to check if a view contains another certain view? I have an AbsoluteLayout view that I add multiple views to (buttons). I have a certain button, let's call it reportButton, and I want to check to see if its already within my AbsoluteLayout view. Is there like an AbsoluteLayout.contains(reportButton) method or something of the kind?

This is what I want to do. "myLayout" is the absolutelayout and "reportAll" is the button.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. class reportAllButtonThread implements Runnable {
  2.  
  3.     //@Override
  4.  
  5.         public void run() {
  6.  
  7.             while(true) {
  8.  
  9.                 if (myLayout.contains(reportAll)) {
  10.  
  11.                     //Do something
  12.  
  13.                 }
  14.  
  15.             }
  16.  
  17.         }
  18.  
  19. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Suggestions?

Thanks.
xspotlivin
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Feb 26, 2009 8:15 am
Location: Cambridge, MA

Top

Postby padde » Sun Apr 19, 2009 1:25 am

Code says more than 1000 words ;)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class test extends Activity {
  3.  
  4.     public void onCreate(Bundle savedInstanceState) {
  5.  
  6.         super.onCreate(savedInstanceState);
  7.  
  8.  
  9.  
  10.         AbsoluteLayout abs = new AbsoluteLayout(this)
  11.  
  12.         Button button1 = new Button(this);
  13.  
  14.         Button button2 = new Button(this);
  15.  
  16.  
  17.  
  18.         abs.addView(button1);
  19.  
  20.  
  21.  
  22.         if(abs.indexOfChild(button1) > -1)
  23.  
  24.             Log.d("","BUTTON1 IS IN.. YEEEHAW");
  25.  
  26.  
  27.  
  28.         if(abs.indexOfChild(button2) > -1)
  29.  
  30.             Log.d("","BUTTON2 IS ALSO IN");
  31.  
  32.         else
  33.  
  34.             Log.d("","BUTTON2 IS OUT");
  35.  
  36.     }
  37.  
  38. }
  39.  
  40.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


should work.. but not tested :)


Greets
Padde
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby xspotlivin » Sun Apr 19, 2009 2:15 am

Thanks, that works.
xspotlivin
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Feb 26, 2009 8:15 am
Location: Cambridge, MA

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests