简体   繁体   中英

How to setVisibility for control in TabActivity from Activity (tab)?

My TabActivity contains ProgressBar and two tabs ( Activities with ListView ).

Where does I must initialize progress = (ProgressBar)findViewById(R.id.progress_bc); and how can I set progress.setVisibility(View.GONE); from onItemClick in ListView in Activity ?

<ProgressBar 
    android:id="@+id/progress_bc"
    android:indeterminate="true" 
    android:layout_width="18dip" 
    android:layout_height="18dip"
    style="@android:style/Widget.ProgressBar.Small"/>

The initialization should be to the Activity where you want to show the dialog. So it is better to have two ProgressBar , one for every layout of your two Activities and control it there.

So in the tab parent Activity (call it CustomTabActivity):

public ProgressDialog dialog;

In the onCreate() you initialize the dialog.

Now when you want to use it from a child Activity, you use:

((CustomTabActivity)getParent()).dialog.show(); or

((CustomTabActivity)getParent()).dialog.dismiss();

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM