2012-05-04 13 views
0

タブバとその仕様を作成しようとしていますが、TabActivityを使用しないでasycnタスクで行う必要があります。以下のコードを実行した後、私はメインレイアウトしか見ません。そして最後に私がやろうとしていることは、アプリケーションがインストールされて初めて必要なファイルが初めてコピーされるというプログレスバーをユーザーに表示したいのですが、その間にファイルをコピーしてtabHostを作成し、仕様を追加します。 asyncTaskがなければ非常にうまくいきますが、アプリケーションを初めて実行すると、コピー処理が完了するまでスクリーンが20秒または30秒間ロックされます。何か案が ?前もって感謝します。Tabhostを作成し、AsyncTaskから仕様を追加する

public class AsyncTest extends AsyncTask<Void, Void, Void> { 

Context context; 
DataBaseJSONFunctions json; 

TabHost tabHost; 

TabWidget tabWidget; 

Resources res; 

TabHost.TabSpec sp; 

Intent intent; 

ProgressDialog dialog; 

Activity ac; 

public AsyncTest(Context context, TabHost tabHost, TabHost.TabSpec sp, Bundle savedInstanceState) { 
    this.context = context; 
    json = new DataBaseJSONFunctions(context); 
    this.tabHost = tabHost; 
    tabWidget = tabHost.getTabWidget(); 
    this.sp = sp; 
    ac = (Activity) context; 
    res = context.getResources(); 

    LocalActivityManager mlam = new LocalActivityManager(ac, false); 
    mlam.dispatchCreate(savedInstanceState); 
    tabHost.setup(mlam); 

} 

@Override 
protected Void doInBackground(Void... params) { 
    initializeAll(); 
    return null; 
} 

@Override 
protected void onPostExecute(Void result) { 

    dialog.dismiss(); 

    // to go through to the another activity in the tab I need to initialize an intent. 
    // and I need to set the Tab bar and it's icon. 
    intent = new Intent().setClass(ac, Activities.class); 
    sp = tabHost.newTabSpec("activities").setIndicator("activities",res.getDrawable(R.drawable.tab_activities_selector)).setContent(intent); 
    tabHost.addTab(sp); 

    // doing the same things for Songs Activity. 
    intent = new Intent().setClass(ac, Promotions.class); 
    sp = tabHost.newTabSpec("promotions").setIndicator("promotions",res.getDrawable(R.drawable.tab_promotions_selector)).setContent(intent); 
    tabHost.addTab(sp); 


    // doing the same things for another Activity. 
    intent = new Intent().setClass(ac,Menu.class); 
    sp = tabHost.newTabSpec("menu").setIndicator("Menu",res.getDrawable(R.drawable.tab_menu_selector)).setContent(intent); 
    tabHost.addTab(sp); 


    intent = new Intent().setClass(ac, Gallery.class); 
    sp = tabHost.newTabSpec("gallery").setIndicator("Gallery",res.getDrawable(R.drawable.tab_gallery_selector)).setContent(intent); 
    tabHost.addTab(sp); 


    intent = new Intent().setClass(ac, Info.class); 
    sp = tabHost.newTabSpec("info").setIndicator("Info",res.getDrawable(R.drawable.tab_info_selector)).setContent(intent); 
    tabHost.addTab(sp); 

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

    tabHost.setCurrentTab(0); 

    // Starting location listener service. 
    ac.startService(new Intent(ac, LocationService.class)); 

    ac.setContentView(R.layout.tabbar_main); 
    super.onPostExecute(result); 
} 

@Override 
protected void onPreExecute() { 
    dialog = ProgressDialog.show(context, "", "Copying files please wait..."); 
    super.onPreExecute(); 
} 
+0

doInBackground()の完了後にonPostExecute()が呼び出されます –

+0

何ですか?何かが間違っている? – osayilgan

+0

あなたはmake tabActivityに別の脅威を使うと思います。 –

答えて

0

私はそれを行うための方法を発見した、私はGONEとして及びonPreExecute()私はVISIBLEとして、この画像の視認性を設定していて、視認性を持っているイメージ図を持っています。また、onPostExecute()と同じようにGoneを作成しています。

0

タブ レイアウトxmlはこのようになります。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TabHost 
     android:id="@android:id/tabhost" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" > 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" /> 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="0" /> 
     </LinearLayout> 
    </TabHost> 


</RelativeLayout> 
+1

私はそのレイアウトではないと思います。私は同じレイアウトを持っていますが、setContentView(R.layout.installation_screen)を呼び出す行にはそのエラーがあります。私はonPreExecute()をやっています。もし私がそれを取り除くならば、すべてが大丈夫です。私は、非同期タスクが実行されている間は、黒い画面の代わりに背景イメージを表示したいだけです。 – osayilgan

関連する問題