开发者

Android: Confining a ProgressDialog to child view

I want to display a ProgressDialog but have it limit its visibility to a child view. As far as I can tell, the ProgressDialog takes up the entire screen and disables accessing any part of the screen until the ProgressDialog is dismissed.

I rolled my own tab control and when the content under one tab is busy doing a lengthy task, I want the ProgressDialog to show only within the content area for that tab. The user can always select another tab while the other tab is busy doing its task and its ProgressDialog is showing.

I suspect that it is not possi开发者_运维知识库ble and will have to roll my own ProgressDialog. However, since the first parameter in creating a ProgressDialog is the context, and is usually set to "this", I was wondering if perhaps the context can be retrieved from a child view but is confined only to the child view. The getContext on a View seems to get the context of the app itself.


you can achieve this in a tricky way, tat worked for me..

In the layout file, which specifies the tab content, put a progress bar as :

<?xml version="1.0" encoding="utf-8"?>
<Layout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" >

        <ListView
            android:id="@+id/updatesList"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
        </ListView>

        <ProgressBar
            android:id="@+id/progressbar"
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
           />
    </FrameLayout>

</LinearLayout>

and in the activity tat displays the tab content, display either the list or progress bar(only one at a time) by :

if(list != null){
            progressBar.setVisibility(View.INVISIBLE);
            updatesListView.setVisibility(View.VISIBLE);
                        adapter = new YourListAdapter(this, list);
            updatesListView.setAdapter(adapter);
        } else{
            progressBar.setVisibility(View.VISIBLE);
            updatesListView.setVisibility(View.INVISIBLE);
            new Thread(downloadListContent).start();
        }

and on completion of download thread, via a handler or runOnUIThread, make the visiblity to reverse as

progressBar.setVisibility(View.INVISIBLE);
updatesListView.setVisibility(View.VISIBLE);


Considering that Android only has one Activity in the foreground at any given time, I believe this may not be possible with normal Activities (may be mistaken though). But I imagine Fragments may be what you are looking for?


The base ProgressDialog takes control of your thread and thus does not allow you to do as you want.

A regular Widget (instead of a Dialog), similar to the normal Progress one or anything you roll on your own can do the trick.

If you already have other content on the tab that is busy and you want to 'cover' that, you can use a Fragment instead..

Easiest to implement would most likely be a Widget that covers your tab content and hiding the other elements.. Nicest in code is using the latter..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜