Andoird.Widget.ProgressBar changing Progress value has no effect, no visible change

LucaGambaLucaGamba USMember
edited March 2017 in Xamarin.Android

Hi all, I'm Luca from Rome, Italy, this is my first question post, sorry for my english.

I'm implementing a very complex application porting from a windows Mobile C# project and I've successfully recompiled all config, fsstorage, crypto, security and othes, classes in a Cross Library project.

Yeah but now I loose on a stupid progress bar .... grrr.

This "Start.axml" layout is used by StartActivity:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/SmartFare" android:id="@+id/imageView1" android:layout_gravity="top" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ValueUpGroup" android:id="@+id/imageView2" android:layout_gravity="center_horizontal" android:layout_marginBottom="0.0dp" android:layout_marginTop="20dp" /> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linearLayoutContainer" android:gravity="center" android:padding="10dp" android:layout_marginTop="10dp"> <LinearLayout android:id="@+id/notify_container" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="8dp" android:background="#DAAA"> <ImageView android:src="@drawable/info_yellow" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="8dp" android:id="@+id/imgNotify" /> <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/linearLayoutTesto"> <TextView android:id="@+id/titleNotify" android:textColor="@color/accent_material_dark" android:text="Titolo notifica" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="match_parent" android:layout_height="wrap_content" /> <TextView android:id="@+id/textNotify" android:textColor="#FFF" android:text="Testo notifica" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout> <ProgressBar style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/progressBarLoading" android:layout_marginTop="10dp" android:progressTint="#ff7fffd4" android:progressTintMode="screen" android:indeterminateTint="#00000000" android:indeterminate="false" android:progress="0" android:secondaryProgress="0" android:secondaryProgressTint="#ffffe4c4" android:secondaryProgressTintMode="screen" android:max="30" /> </LinearLayout> <!-- style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal" --> </LinearLayout>

I've declared the bar object and a timer into StartActivity (splash fullscreen):
[Activity(MainLauncher = true, Icon = "@drawable/Icon", NoHistory = true, Theme = "@style/MyTheme.Splash", ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait )] public class StartActivity : Activity { Timer progressTimer; ProgressBar progressBar; int seconds=0; ...

I've inizialized the bar into OnCreate override:
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Start); progressBar = FindViewById<ProgressBar>(Resource.Id.progressBarLoading); progressBar.Max = 100; progressBar.Progress = 0; progressBar.SecondaryProgress = 0; progressBar.Visibility = ViewStates.Visible; progressBar.Enabled = true; progressBar.Indeterminate = false; ...
I'vew tried to add and change properties ... no effect.

I've started a thread into OnResume override:
protected override void OnResume() { base.OnResume(); ... // background Task Task startupWork = new Task(() => { ... a lot of init code various classes // connect to server showing progress bar: progressBar.Max = SyncManager.Instance.defaultTimeOut; // 30 sec progressBar.SetProgress(0, true); progressTimer = new Timer(); progressTimer.Interval = 1000; // 1 sec progressTimer.Elapsed += OnTimeEvent; progressTimer.Enabled = true; progressTimer.Start(); RxDataLoaded = FsStorage.Instance.UpdateAllXMLResource(true); progressTimer.Stop(); progressTimer.Dispose(); ...
This in OnTimeEvent method called every 1 second (call verified by breackpoint):
private void OnTimeEvent(object sender, ElapsedEventArgs e) { RunOnUiThread(() =>{ //progressBar.IncrementProgressBy(1); seconds++; progressBar.SetProgress(seconds, true); }); }

I've try various modes (IncrementProgressBy, SetProgress, Progress=) but i've no effect visible, progress bar not change.

This becase calling SetContentView(Resource.Layout.Start); in another method to change labels I suppose.

Luca

Best Answer

  • LucaGambaLucaGamba US
    edited March 2017 Accepted Answer

    Yes .... I'm so lammah.

    Solved declaring imageView e textView global in the class and removed SetContentView(Resource.Layout.Start); from here:
    `private void NotificaStato(int step, string title, string message, MessageBoxIcon icon = MessageBoxIcon.Information)
    {
    RunOnUiThread(() => {
    // REMOVED code here
    imgNotifica.SetImageResource(MessageBox.getIconResource(icon));
    titNotifica.Text = title;
    txtNotifica.Text = message;

                var progressBar = FindViewById<ProgressBar>(Resource.Id.progressBarLoading);
                //progressBar.IncrementProgressBy(10);
                int progress = (step * progressBar.Max) / maxSteps;
                progressBar.SecondaryProgress = progress;
            });
        }
    

    `

Answers

  • LucaGambaLucaGamba USMember
    edited March 2017 Accepted Answer

    Yes .... I'm so lammah.

    Solved declaring imageView e textView global in the class and removed SetContentView(Resource.Layout.Start); from here:
    `private void NotificaStato(int step, string title, string message, MessageBoxIcon icon = MessageBoxIcon.Information)
    {
    RunOnUiThread(() => {
    // REMOVED code here
    imgNotifica.SetImageResource(MessageBox.getIconResource(icon));
    titNotifica.Text = title;
    txtNotifica.Text = message;

                var progressBar = FindViewById<ProgressBar>(Resource.Id.progressBarLoading);
                //progressBar.IncrementProgressBy(10);
                int progress = (step * progressBar.Max) / maxSteps;
                progressBar.SecondaryProgress = progress;
            });
        }
    

    `

Sign In or Register to comment.