1 Replies - 235 Views - Last Post: 27 October 2018 - 06:26 PM

#1 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

XAMARIN: Syntax of GetChildAt ?

Posted 20 October 2018 - 09:22 AM

Hey all,
I've seen this around, but I'm not sure those integers in GetChildAt arg are referring to. There are three of them... I know that when I change them, the program finds a different view, but what purpose does each individual int do?

                      var parentView = ((ViewGroup)((ViewGroup)tabHost.GetChildAt(0)).GetChildAt(1)).GetChildAt(1);



It's a method for getting a tab layout in xamarin/java/android but the MSDN information is lacking. I found some interesting java documentation, but I really don't understand java syntax.

If I change the first int, the app crashes.

If I change the last int, my app reloads the webview when I tap the tab farthest left, but only when the tab directly right of it is already selected.

Here's the greater context

        public class MyonclickListener : Java.Lang.Object, IonclickListener
        {
            TabHost tabHost;

            public MyonclickListener(TabHost tabHost)
            {
                this.tabHost = tabHost;
            }

            public void onclick(View v)
            {

                      var parentViewSubs = ((ViewGroup)((ViewGroup)tabHost.GetChildAt(0)).GetChildAt(1)).GetChildAt(1);


                WebView subsWebView = parentViewSubs.FindViewById<WebView>(Resource.Id.webViewSubs);


                subsWebView.Reload();


                tabHost.CurrentTab = 1;
            }
        }



Is This A Good Question/Topic? 0
  • +

Replies To: XAMARIN: Syntax of GetChildAt ?

#2 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: XAMARIN: Syntax of GetChildAt ?

Posted 27 October 2018 - 06:26 PM

Answer to this is the int represents which tab the GetChildAt() method will be returned or listening on. Also, I wouldn't recommend using that parentview. I'm still not sure what all those three ints do.. but I know that changing the first int will crash the app, changing the second will also crash the app, changing the third changes which tab reacts to your code. And, here's what GetChildAt would do when used in the context of a TabWidget

Each instance has a different int from 0 to 4 ... there are 5 total tabs in my solution. 0 represents the tab farthest left, 1 is second from the left and so on.

            tabHost.TabWidget.GetChildAt(0).SetonclickListener(new WhatsonclickListener(tabHost));

            tabHost.TabWidget.GetChildAt(1).SetonclickListener(new SubsClickListener(tabHost));

            tabHost.TabWidget.GetChildAt(2).SetonclickListener(new DiscoverClickListener(tabHost));

            tabHost.TabWidget.GetChildAt(3).SetonclickListener(new MyChannelClickListener(tabHost));

            tabHost.TabWidget.GetChildAt(4).SetonclickListener(new SettingsClickListener(tabHost));



Each instance also has it's own tab listener class, but I digress.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1