Reputation: 16532
I have a class for my TabActivity
public class DashboardActivity extends TabActivity
This has several tabs and an actionbar. One of these tabs is a list of items.
public class WalletActivity extends ExpandableListActivity
I want to be able to run an asynchronous task in one of the child activities, and while it is running have the spinner show in my actionbar. I already do this within an AsyncTask
in my tab activity
ActionBar actionBar = (ActionBar)findViewById(R.id.actionbar);
if(actionBar != null)
actionBar.setProgressBarVisibility(View.VISIBLE);
How can I reference the DashboardActivity
that is hosting my tabbed WalletActivity
?
Upvotes: 3
Views: 1261
Reputation: 7082
I have a small method that recieves an Activity and returns the current context. If the Activity has a parent (the TabActivity, an ActivityGroup, etc), it returns that context in order to show the spinner/dialog/whatever in there.
public Context getDialogContext(Activity act) {
Context context;
if (act.getParent() != null)
context = act.getParent();
else context = act;
return context;
}
Upvotes: 4