Solved

In a loop through all Childs on my LinearLayout, how can i separte the buttons ? what am i missing in the following code

Posted on 2014-09-10
2
145 Views
Last Modified: 2014-10-03
Hello,

I'm working on some tests and i would like to be sure that in my NiceActivity there is four buttons that are displayed.
In this activity i also have textEdit view.

I'd like to separete - count - my buttons in a test but when i try to check if a view is a button I can not pass my test.


Here 's my method :
commented are two test that didnot work. In my debug i can see that the v.getClass().getSimpleName() is "Button" but if I compare it to "Button" i receive false.....help ;)




private ArrayList<Button> GetOnlyButtonsOutOfLayout(LinearLayout aLinlayout) {
        ArrayList<Button> response = new ArrayList<Button>();
        int childcount = aLinlayout.getChildCount();
        Log.i(_className, "fils de layout: " + childcount);

        for (int i=0; i < childcount; i++){
            View v = aLinlayout.getChildAt(i);
            //if(v.getClass().getSimpleName().toString() == "Button" ){
            //if(v.getClass().getSimpleName() == Button.class.getSimpleName() ){
            Log.i(_className, v.getClass().getSimpleName());
            if(v.getClass().getSimpleName() == "Button"){
                response.add((Button) v);
            }
        }
        return response;
    }


my response is always empty.

how can i do this.

thank you in advance for your help.

toshiro
0
Comment
Question by:toshi_
  • 2
2 Comments
 

Accepted Solution

by:
toshi_ earned 0 total points
ID: 40359331
i've added a new layout in order to have all  buttons separted.
since then i could easily pass my test.

toshi
0
 

Author Closing Comment

by:toshi_
ID: 40359334
could not cast view elements to know what they were , if they were button or textview....
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I tend toward trying the newest hardware and software.  Thiss sometimes works out to my benefit, and sometimes not.  Because I downloaded and installed Android 5.x (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.htm…
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question