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
147 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I recently asked a question (http://www.experts-exchange.com/Programming/Smartphones/Android/Q_28684946.html) about Computer Inventory applications for Mobile Devices.  I was specifically interested in an app I could use on my android phone.  The be…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
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.

829 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