I'm using navigation drawer template from Xamarin
and it working perfectly. So I can change layout dynamically. Now, I need to change fragment directly from single button (like shortcut). Changing between fragments works differently not like simple activity. In activity I can do simple code to change activity through a button:
Intent nextActivity = new Intent(this, typeof(ItemAddFormActivity));
StartActivity(nextActivity);
But, how to change fragment layout from single button? I'm still searching how to change fragment between fragment with button.
Maybe someone here can help me. Thanks in advance.
This is how i have implemented in my solution, might help you
this is my fragment
public class Fragment3 : Fragment
{
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your fragment here
}
public static Fragment3 NewInstance()
{
var frag1 = new Fragment3 { Arguments = new Bundle() };
return frag1;
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var ignored = base.OnCreateView(inflater, container, savedInstanceState);
return inflater.Inflate(Resource.Layout.fragment3, null);
}
}
To Display Fragment on button event use this
Android.Support.V4.App.Fragment fragment = null;
fragment = Fragment3.NewInstance();
if (fragment == null)
return;
SupportFragmentManager.BeginTransaction()
.Replace(Resource.Id.content_frame, fragment)
.Commit();