サーバーからのデータのリストを使用して BaseExpandableListAdapters を構築する必要があります。この値のリストを取得するために AsyncTask を使用しています。現在、DoInBackGround オーバーライド メソッドから BaseExpandableListAdapter を返すことができないため、パブリック プロパティを使用しています。以下のコードで、次のいずれかを実行できます。
- AsyncTask クラスの My および Market プロパティを取得して、期待されるすべての値を返しますが、タスクが実行されて役に立たなくなるまで ProgressDialog が表示されない、または
- ProgressDialog を取得して、必要に応じてすぐに表示されますが、リストビューにアダプターを割り当てるために My プロパティと Market プロパティを使用しようとすると、それらのプロパティが空になります
私は両方を達成する必要があります。
public class Work : Activity
{
private ExpandableListView market;
private ExpandableListView my;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Work);
market = (ExpandableListView)FindViewById(Resource.Id.market);
my = (ExpandableListView)FindViewById(Resource.Id.my);
PopulateWorkListViews populate = new PopulateWorkListViews(this);
populate.Execute(techID, market, userType);
//Removing the following line allows for the ProgressDialog but the Market
//and My properties of the PopulateWorkListViews class are empty as opposed
//to leaving this line in and both properties contain all expected values
//but ProgressDialog doesn't show up.
string result = populate.Get().ToString();
market.SetAdapter(populate.Market);
my.SetAdapter(populate.My);
}
}
public class PopulateWorkListViews : AsyncTask
{
private Context Context { get; set; }
private ProgressDialog Dialog { get; set; }
public BaseExpandableListAdapter Market { get; set; }
public BaseExpandableListAdapter My { get; set; }
public PopulateWorkListViews(Context context)
{
Context = context;
}
protected override void OnPreExecute()
{
Dialog = new ProgressDialog(Context);
Dialog.SetMessage("Processing...");
Dialog.Window.SetGravity(GravityFlags.Center);
Dialog.SetCancelable(false);
Dialog.Indeterminate = true;
Dialog.SetProgressStyle(ProgressDialogStyle.Spinner);
Dialog.Show();
}
protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] @params)
{
WS ws = new WS();
List<ServiceCall> calls = ws.GetMarketCalls(@params[0].ToString(), @params[1].ToString(), @params[2].ToString()).ToList();
Market = new MarketCallListView(Context, calls);
My = new MyCallListView(Context, calls, @params[0].ToString());
return "Done";
}
protected override void OnPostExecute(Java.Lang.Object result)
{
Dialog.Dismiss();
}
}