Forum Xamarin.Android

Progressbar is not spinning in fragment

la.tanblala.tanbla USMember ✭✭

Hi,

I have an activity that uses the support ViewPager. The ViewPager uses a custom adapter that contains two fragments. The fragments both load the same layout file which contain a progress bar inside of a relative layout. The progress bar is displayed when the activity starts, but it doesn't animate until the activity resumes, either from a screen rotation, app switch or any other reason. Any idea what the matter might be? My code seems kind of standard to me, which is why I'm not posting it now but if you would like a look at it to help out let me know and I'd be happy to.

Thanks

Answers

  • la.tanblala.tanbla USMember ✭✭

    Anyone?

  • ashalvaashalva GEMember ✭✭✭

    I think I would help if you post the snippet where how and where you are calling the progressbar animation?

  • la.tanblala.tanbla USMember ✭✭
    edited April 2016

    I am not actually "calling" the progressbar animation, I just expected the indeterminate progressbar to automatically be animated once it is added to a layout.

    Relevent Code:

    JobListFragment Layout File:

    <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ViewSwitcher android:id="@+id/emptyListDisplay" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_centerVertical="true" android:layout_centerHorizontal="true"> <ProgressBar android:layout_width="match_parent" android:layout_height="wrap_content" android:indeterminate="true" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="No jobs to display" android:textColor="#ff616161" android:textSize="24sp" /> </ViewSwitcher> <ListView android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/jobList" android:layout_marginTop="8dp" /> </RelativeLayout>

    JobListFragment Class:

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        var view = inflater.Inflate(Resource.Layout.JobListFragment, container, false);
    
        JobList = view.FindViewById<ListView>(Resource.Id.jobList);
    
        EmptyView = view.FindViewById<ViewSwitcher>(Resource.Id.emptyListDisplay);
        JobList.EmptyView = EmptyView;
    
        JobList.ItemClick += (sender, eventArgs) => 
            {
            var adapter = JobList.Adapter as JobListAdapter;
                Intent viewJobIntent = new Intent(Activity, typeof(JobViewActivity));
                viewJobIntent.PutExtra("job", JsonConvert.SerializeObject(adapter[eventArgs.Position]));
                StartActivity(viewJobIntent);
                // OverridePendingTransition(Android.Resource.Animation.SlideInLeft, 0);
            };
    
        return view;
    }
    

    JobListActivity Layout:

     <RelativeLayout
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent">
         <android.support.v7.widget.Toolbar
             android:id="@+id/toolbar"
             android:layout_width="match_parent"
             android:layout_height="56dp"
             android:background="?attr/colorPrimary"
             android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
             app:theme="@style/ThemeOverlay.AppCompat"
             app:popupTheme="@android:style/Theme.Holo.Light" />
         <android.support.design.widget.TabLayout
             android:id="@+id/tabLayout"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_below="@id/toolbar"
             android:background="?attr/colorPrimary"
             android:scrollbars="horizontal"
             app:layout_scrollFlags="scroll|enterAlways"
             app:theme="@style/ThemeOverlay.AppCompat"
             android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
         <android.support.v4.view.ViewPager
             android:id="@+id/pages"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_below="@id/tabLayout" />
    </RelativeLayout>
    

    JobListActivity Class:

        private void InitPager()
        {
            pager = FindViewById<ViewPager>(Resource.Id.pages);
            pager.Adapter = new JobListFragmentAdapter(SupportFragmentManager);
        }
    
        private void InitTabs()
        {
            tabLayout = FindViewById<TabLayout>(Resource.Id.tabLayout);
            tabLayout.TabGravity = TabLayout.GravityFill;
            tabLayout.SetupWithViewPager(pager);
         }
    

    JobListFragmentAdapter:

    public class JobListFragmentAdapter : FragmentStatePagerAdapter
    {
        public List<JobListFragment> JobLists
        {
            get;
            protected set;
        }
    
        private string[] JobTitles = new string[]
            {
                "Active Jobs",
                "Completed Jobs"
            };
    
        private Action OnFinish;
    
        public JobListFragmentAdapter(FragmentManager fm, Action onFinish = null) : base(fm)
        {
            JobLists = new List<JobListFragment>();
            JobLists.Add(JobListFragment.NewInstance(true));
            JobLists.Add(JobListFragment.NewInstance(false));
    
            OnFinish = onFinish;
        }
    
        public override int Count
        {
            get
            {
                return JobLists.Count;
            }
        }
    
        public override Fragment GetItem(int position)
        {
            return JobLists[position];
        }
    
        public override Java.Lang.ICharSequence GetPageTitleFormatted(int position)
        {
            var builder = new SpannableStringBuilder();
            builder.Append(JobTitles[position]);
    
            return builder;
        }
    
        public override void FinishUpdate(Android.Views.ViewGroup container)
        {
            base.FinishUpdate(container);
    
            if (OnFinish != null)
                OnFinish();
    
        }
    }
    

    I believe that is everything that should have a bearing on the progressba, but if not I will gladly post anything else. Thanks for your help.

Sign In or Register to comment.