2012-05-03 36 views
1

我已經建立其開始從應用程序複製的圖像和一些數據到內存中,一旦應用程序正在運行的應用程序第一次。然後稍後在其他活動的其他地方使用這些數據。的TabBar與異步任務的Android

複印處理時間超過30秒。所以我想在異步任務中做到這一點。但我無法讓它工作。異步任務運行良好,但我需要創建選項卡規範並將意向分配給onPostExecute方法中的每個規範。但我看到的只是沒有規格的標籤欄,沒有任何作用。

所以任何想法如何建造它以這種方式?

任何幫助將不勝感激。 這裏我的活動是,

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

    myJSON = new DataBaseJSONFunctions(this); 

    TabHost tabHost = getTabHost(); 

    TabWidget tabWidget = tabHost.getTabWidget(); 

    Resources res = getResources(); 
    //TabHost tabHost = getTabHost(); 

    TabHost.TabSpec spec; 
    Intent intent; 

    // Starting Initialization process. 
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); 

    if(!prefs.getBoolean("firstRun", false)) { 

     initializeAll(); 
     // Set "firstRun" true to make it runs once application is installed. 
     prefs.edit().putBoolean("firstRun", true).commit(); 
    } 

而且我想把這個塊異步任務,

intent = new Intent().setClass(this,Activities.class); 
    spec = tabHost.newTabSpec("activities").setIndicator("act",res.getDrawable(R.drawable.tab_activities_selector)).setContent(intent); 
    tabHost.addTab(spec); 

    // doing the same things. 
    intent = new Intent().setClass(this, Promotions.class); 
    spec = tabHost.newTabSpec("promotion").setIndicator("Promotion",res.getDrawable(R.drawable.tab_promotions_selector)).setContent(intent); 
    tabHost.addTab(spec); 


    // doing the same things for Albums Activity. 
    intent = new Intent().setClass(this,Menu.class); 
    spec = tabHost.newTabSpec("menu").setIndicator("Menü",res.getDrawable(R.drawable.tab_menu_selector)).setContent(intent); 
    tabHost.addTab(spec); 

    for(int i = 0; i < tabWidget.getChildCount(); i++){ 
     tabWidget.getChildAt(i).setBackgroundResource(R.drawable.tab_bar); 
    } 

    tabHost.setCurrentTab(0); 

順便說一句,蔭通過我的活動範圍內,以異步任務。

回答

0

試圖從AsyncTask填充TabHost有點標新立異。我建議儘快您的應用程序啓動填充TabHost與標籤,然後運行AsyncTask,這可能會或可能不會顯示ProgressDialog讓用戶知道的東西是怎麼回事,和你的AsyncTask完成後,您可以填寫您的使用新數據的用戶界面。

+1

,我會盡快嘗試,但事情是如果我一旦應用程序啓動後我會怎麼做填充的TabBar?我的意思是我需要從AsyncTask返回的數據來填充UI。如果我開始沒有數據的意圖,我會得到空指針。 – osayilgan

+0

如果這是您的第一次運行,您可以使用之前運行中保存的數據或手動製作的佔位符數據。關鍵是,你的用戶界面應該顯示一些東西,然後你可以開始後臺更新,並可能顯示「ProgressBar」來告訴用戶正在發生的事情。 – lenik