Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

ListView in Dialog Fragment

OmarMohOmarMoh USMember ✭✭
edited March 2016 in Xamarin.Android

Hi

i created dialog fragment and i want when user click the button the dialog fragment show list view , how can i do this ?

Answers

  • TripleDoubleTripleDouble BGMember ✭✭✭

    Hello.

    I have a similar problem here https://forums.xamarin.com/discussion/95546/how-to-add-a-fragment-in-customadapter#latest.

    Did you find a solution ?

  • cwphillicwphilli USMember ✭✭✭

    To show a fragment, it typically looks like the following:

    var transaction = FragmentManager.BeginTransaction();
    var fragment = new MyFragment();
    fragment.Show(transaction, Tag);
    

    You will want to have a layout container that you'd like the fragment to replace, I use a utility function like so (named better ;) ):

        public static Fragment ShowMyFragment(FragmentManager manager, int containerId, string tagId)
        {
            var ft = manager.BeginTransaction();
    
            // remove existing copies of fragment
            var prev = manager.FindFragmentByTag(tagId);
            if (prev != null)
                ft.Remove(prev);
    
            var fragment = MyFragment.NewInstance(containerId, tagId);
            ft.Replace(containerId, fragment, tagId);
            ft.Commit();
            return fragment;
        }
    
Sign In or Register to comment.