Problem using fragment

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?

Answers

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    Any chance you can post logcat output or a stack trace?

  • KeesPaulKeesPaul NLMember ✭✭

    You mean the application output as shown in Xamarin?

    It did find one thing: I forgot to remove an attribute to a Click event handler in the .axml file. I removed it and the application does not stop anymore. But it doesn't show the fragment as well. Again this could be my ignorance. Buy the way, the output shows some messages I do not understand, maybe they are minor issues, maybe not. If you want me to copy it I will.

  • KeesPaulKeesPaul NLMember ✭✭

    Solved my problem. I forgot to add false to the inflater as third parameter. Now it works fine.

Sign In or Register to comment.