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

Problem using fragment

$
0
0

Hi All,

As a newcomer to Xamarin (and Android) I am trying to use fragments as it seems the approach for a project I am porting from Windows to Android.

For some reason (most likely my ignorance regarding Android and Xamarin) I can not implement a fragment. After reading numerous links on how to do this I am still not able to figure out what is wrong. I finally found a very neat example in Java and I tried to mimic this in c# and Xamarin. There must be a simple factor (or more) that I am constantly overlooking. On an button click I handle the fragment installing. The code in my activity is as follows:

    public void OnClick(View Sender)
    {
        if (Sender != _contract_button)
            return;
        FragmentManager fragman = FragmentManager;
        FragmentTransaction fragman_trans = fragman.BeginTransaction();
        _getcontractfragment = new GetContract();
        fragman_trans.Add(Resource.Id.totallayout, _getcontractfragment);
        fragman_trans.Commit();
    }

In the fragment source I have the following code:

    public override View OnCreateView(LayoutInflater Inflater, ViewGroup Container, Bundle savedInstanceState)
    {
        View GetContractView = Inflater.Inflate(Resource.Layout.getcontract, Container);
        RadioButton _north_button = GetContractView.FindViewById<RadioButton>(Resource.Id.radionorth);
        _north_button.Checked = true;
        return(GetContractView);
    }

The program ends after clicking the button with the message that the program has stopped. Using the debugger I see no specific reason why. It goes through all the expected code and returns from the OnClick handler to halt. The layouts are both in .axml files and seem(?) to be okay. So no error (at least no one that is reported otherwise), but the program ends unexpectdly.

Anyone an idea where to look and how to solve this?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



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