Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How to bind a handler to a button in a fragment ?

$
0
0

My app uses three tabs (bottom navigation), the three fragments associated to the three tabs are loaded from a fragment manager. When the app starts, it shows the first tab/fragment. I have a button on the third tab. How can I attach a handler to it ? If I try to do it from within the fragment's code, the code

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var ignored = base.OnCreateView(inflater, container, savedInstanceState);

            var view = inflater.Inflate(Resource.Layout.fragment_options, null);
            myButton = view.FindViewById<Button>(Resource.Id.myButton);
            myButton.Click += buttonHandler;
            return view;
        }

Will always assigne "null" to "myButton", thus can't handle the button.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>