2012-07-03 68 views
0

Tabbar中的ProgressDialog android

我想在android中製作一個標籤欄應用程序,在google中搜索後我發現了一些教程並且我成功了。我需要3個選項卡,當我點擊第一個選項卡時,將使用asyntask從服務器獲取一些數據,並在前端顯示progressdialog,但progressdialog捕獲整個屏幕(帶tabbar),因此我無法切換第二個或第三個標籤。

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> 

+0

後,你可以發送一些代碼,我們可以明白的地方你就錯了。 – osayilgan

回答

0

只是把進度爲孩子Activitys要添加在TabHost。

首先,它會顯示在的onCreate第一項活動已設爲當前活動的進度條,如果你點擊一個選項卡上會顯示其進度對話框

+0

在第一個選項卡中,我創建了一個活動,並在該活動中編寫了一個progressdialog代碼,如下所示: - ProgressDialog dialog = new ProgressDialog(getParent()); \t \t \t dialog.setMessage(「LOADING ...」); \t \t \t dialog.setCancelable(false); \t \t \t dialog.show(); 但我不能夠切換選項卡。 – Pradeep

0

如果我沒有得到你,你需要訪問以下當進度對話框是活動的時候,

爲此您需要製作非模態/無模進度對話框。非模態對話框將允許你通過後面的UI組件接受事件

請參考下

timed modeless dialog

+0

我試圖添加一個標誌 - > dialog.getWindow()。addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); 但進度對話框顯示在下一個標籤 – Pradeep

+0

請張貼您的代碼。我想你也在另外兩個標籤中調用了相同的'Asynctask'。這一定是你的合乎邏輯的問題。但通過上面的代碼,您可以訪問'ProgressDialog'下的UI組件。我對嗎 ? – sunil

+0

順便說一句,我只是想在第一個選項卡progressdialog和那個時候我想能夠訪問第二個選項卡,如果你想我的代碼編輯我的問題 – Pradeep