i have done through tablistner and storing chat information in static list,

    /// <summary>
    /// Listener that handles the selection of a tab in the user interface
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class TabListener<T> : Java.Lang.Object, ActionBar.ITabListener
        where T : Fragment
    {
        private T _fragment;
       
        /// <summary>
        /// Initializes a new instance of the tab listener
        /// </summary>
        /// 
        public TabListener(T fragment)
        {
            _fragment = fragment;
        }

        /// <summary>
        /// Handles the reselection of the tab
        /// </summary>
        /// 
        /// 
        public void OnTabReselected(ActionBar.Tab tab, FragmentTransaction
ft)
        {
            
        }

        /// <summary>
        /// Adds the fragment when the tab was selected
        /// </summary>
        /// 
        /// 
        public void OnTabSelected(ActionBar.Tab tab, FragmentTransaction ft)
        {
            Fragment fragment = null;
            if (tab.Text == "Users")
            {
                fragment = Global.UserFragment;
            }
            else
            {
                fragment = Global.ChatWindows.FirstOrDefault(chat =>
chat.User.Name == tab.Text);
                tab.SetIcon(Resource.Drawable.message);
            }

            Global.CurrentFragment = fragment;
            FragmentManager fm = Global.QActivity.FragmentManager;
            fm.BeginTransaction().Add(Resource.Id.Frame_container, fragment,
tab.Text).Commit();
        }

        /// <summary>
        /// Removes the fragment when the tab was deselected
        /// </summary>
        /// 
        /// 
        public void OnTabUnselected(ActionBar.Tab tab, FragmentTransaction
ft)
        {
            Fragment fragment = null;
            if (tab.Text == "Users")
            {
                fragment = Global.UserFragment;
            }
            else
            {
                fragment = Global.ChatWindows.FirstOrDefault(chat =>
chat.User.Name == tab.Text);
                tab.SetIcon(Resource.Drawable.QChatOffline);
            }

            FragmentManager fm = Global.QActivity.FragmentManager;
            fm.BeginTransaction().Remove(fragment).Commit();
        }
    }

and when message get from other user or we select user to chat then i
handled it using below

try
            {
                User user = GetUserByName(userName);
                ChatFragment chatFragment =
Global.ChatWindows.Find(chatWindow => chatWindow.User.Name == user.Name);
                var ft = this.activity.FragmentManager.BeginTransaction();
                if (chatFragment == null)
                {
                    chatFragment = new ChatFragment();
                    chatFragment.User = user;
                    chatFragment.CurrentUser = Global.Host.Username;

                    var chatTab = this.activity.ActionBar.NewTab();
                    chatFragment.TabListener = new
TabListener<ChatFragment>(chatFragment);
                    chatTab.SetTabListener(chatFragment.TabListener);
                    chatTab.SetIcon(Resource.Drawable.message);
                    chatTab.SetText(userName);
                    // Add the new tab to the action bar
                    this.activity.ActionBar.AddTab(chatTab);
                    ft.Add(Resource.Id.Frame_container, chatFragment,
user.Name);
                    Global.ChatWindows.Add(chatFragment);

                    this.activity.ActionBar.SelectTab(chatTab);

                    Global.CurrentFragment = chatFragment;
                    ft.Commit();
                }
                else
                {
                    int index = Global.ChatWindows.FindIndex(chat =>
chat.User.Name == chatFragment.User.Name);
                    ActionBar.Tab tab =
this.activity.ActionBar.GetTabAt(index + 1);
                    tab.SetIcon(Resource.Drawable.message);
                    if (selectedFromList)
                    {
                        ft.Remove(chatFragment);
                        ft.Commit();
                        Global.CurrentFragment = chatFragment;

                        try
                        {
                            var fragmentTransaction =
this.activity.FragmentManager.BeginTransaction();
                            this.activity.ActionBar.SelectTab(tab);
                            fragmentTransaction.Commit();
                        }
                        catch (Exception ex)
                        {

                        }
                    }
                    else
                    {
                        ft.Remove(chatFragment);
                        ft.Add(Resource.Id.Frame_container, chatFragment,
user.Name);
                        ft.Commit();
                    }
                }


I hope if anyone wants single activity with multiple fragments using action
bar tab then it will help.



--
View this message in context: 
http://mono-for-android.1047100.n5.nabble.com/Switch-between-fragmnets-action-bar-tab-interface-tp5711339p5711704.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to