Tabbar android中的ProgressDialog

时间:2012-07-03 07:03:52

标签: android progressdialog android-tabs

    我想在android中制作一个标签栏应用程序,在谷歌搜索后我发现了一些教程,我成功了。我想要3个标签,当我点击第一个标签时,一些数据将使用asyntask从服务器中获取并在前端显示progressdialog,但progressdialog正在捕获整个屏幕(使用tabbar),因为我无法切换第2或第3个标签。

Expected Output: Whenever i click on any tab a data will be taken from server in background, as i know data is loaded in background so for that time i want to switch 2nd tab or any other tab. 


package com.tabexample;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;

import android.view.View;
import android.view.View.OnClickListener;

import android.view.WindowManager;
import android.widget.Button;

public class ArrowsActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.arrowspage);

        Button back = (Button) findViewById(R.id.BackButton2);



       back.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            ProgressDialog p = new ProgressDialog(getParent());
            p.setMessage("Loading");
            p.setCancelable(false);
            p.show();
            p.getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);

        }
    });


    }
}



package com.tabexample;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;


public class EditActivity extends ListActivity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, mListContent));   
        ListView lv = getListView();
        lv.setOnItemClickListener(new OnItemClickListener() 
        {
             public void onItemClick(AdapterView<?> parent, View view, int position, long id)
             {
                 startActivity(new Intent(EditActivity.this, OptionsActivity.class));
             }
        }); 


    }


    private static String[] mListContent={"Item 1", "Item 2", "Item 3"};
}



package com.tabexample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;

public class OptionsActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.optionspage);

        Button back = (Button) findViewById(R.id.BackButton1);
        Button next = (Button) findViewById(R.id.NextButton1);


    }
}

package com.tabexample;


import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;



public class TabExmapleActivity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tablayout);
        TabHost tabHost = getTabHost();       

        tabHost.addTab(tabHost.newTabSpec("tab1")
              .setIndicator("OPT")
              .setContent(new Intent(this, ArrowsActivity.class)));

        tabHost.addTab(tabHost.newTabSpec("tab2")
              .setIndicator("EDIT")
              .setContent(new Intent(this, EditActivity.class)));

        tabHost.setCurrentTab(0);
    }
}




<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout02" android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <TextView android:id="@+id/TextView02" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="Arrows Page">
    </TextView>
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/BackButton2"
        android:text="Back" android:layout_below="@+id/TextView02">
    </Button>

<Button android:id="@+id/Button01" android:layout_below="@id/BackButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Indeterminate Dialog"></Button>
<Button android:id="@+id/Button02" android:layout_below="@id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Select"></Button>
</RelativeLayout>






<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout01" android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="Options Page">
    </TextView>
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/BackButton1"
        android:text="Back" android:layout_below="@+id/TextView01">
    </Button>
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/NextButton1"
        android:text="Next" android:layout_toRightOf="@+id/BackButton1"
        android:layout_below="@+id/TextView01"></Button>
</RelativeLayout>





<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" >
        </FrameLayout>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true">
        </TabWidget>
    </RelativeLayout>

</TabHost>



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tabexample"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".TabExmapleActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="ArrowsActivity"></activity>
        <activity android:name="EditActivity"></activity>
        <activity android:name="OptionsActivity"></activity>
    </application>

</manifest>

2 个答案:

答案 0 :(得分:0)

为TabHost中添加的子活动添加进度条。

首先,它将显示onCreate中您设置为当前活动的第一个活动的进度条,如果您单击下一个选项卡,它将显示其进度对话框

答案 1 :(得分:0)

如果我找到你,你需要在进度对话框激活时访问以下活动组件。

为此你需要进行非模态/无模式进度对话框。非模态对话框将允许您通过ui组件后面的事件接受

请参阅下面的帖子

timed modeless dialog

相关问题