문제

Could you help me with following problem? I have some code:

button.Click += (sender, e) => Search_Click();

....

void Search_Click() 
{   
    // here i'am trying to clear some ListView
    var list = FindViewById<ListView> (Resource.Id.terminalsList);  
    list.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, new List<string>());

    // here i am trying to show ProgressDialog
    ProgressDialog progress = new ProgressDialog(this);         
    progress.SetMessage("Wait while loading...");
    progress.Show();

   // but here i haven't ProgressDialog and clear ListView yet

   ......

    // another code
}

But this code does not work properly. This code is perfomed after the Search_Click method finished but i want this code to be perfomed immediately.How can i do it?

thanks in advance

도움이 되었습니까?

해결책

A wait dialog indicates this is a long running process. Have you tried async await?

        button.Click += async delegate
        {
            await Search_Click();
        };
    }

    Task Search_Click() 
    {   
        return Task.Factory.StartNew (() =>
        {
            // here i'am trying to clear some ListView

            // here i am trying to show ProgressDialog
            var progress = new ProgressDialog (this);         
            progress.SetMessage ("Wait while loading...");
            progress.Show ();

            // but here i haven't ProgressDialog and clear ListView yet

            progress.Dismiss();
        });
    }

다른 팁

You need to notify your ListView whenever you change the adapter (or its data). Check the answer to this post change ImageView Resource in a ListView Layout from an AsyncTask that load contactsList

Good luck

You need to reload your listview to see the affected changes in Listview.

List view works on the myAdapter.notifyDataSetChanged() method for reloading and refreshing

Here you can just create any method in you adpater with mAdapterobj.notifyDataSetChanged() so the Listview will know the data is changing now You can this method after your setadpater() method too,

And for your progress dialog you can just allocate obj and all the required stuff outside of search click and just use Show() and Hide method work in Progress dialog

Hope It may help you

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top