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
138 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
Comment Utility
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_
Comment Utility
could not cast view elements to know what they were , if they were button or textview....
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now