0

我正在尝试在android中制作一个标签栏应用程序,在谷歌搜索后我找到了一些教程并且我成功了。我想要 3 个选项卡,当我单击第一个选项卡时,将使用 asyntask 从服务器获取一些数据并在前端显示进度对话框,但进度对话框正在捕获整个屏幕(带有选项卡栏),因此我无法切换第二个或第三个选项卡。

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>

4

2 回答 2

0

只需将您要添加的子 Activity 的 Progressbar 放在 TabHost 中。

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

于 2012-07-03T07:09:29.743 回答
0

如果我理解正确,您需要在进度对话框处于活动状态时访问以下活动组件。

为此,您需要制作非模态/无模态进度对话框。非模态对话框将允许您通过 ui 组件接受事件

请参考下面的帖子

定时无模式对话

于 2012-07-03T07:15:57.560 回答