2011-01-03 13 views
0

サーバーからデータをダウンロードするアプリケーションを作成する際に問題が発生します。私がしたいのは、ユーザーがタブホスト内からタブをクリックしたときにいくつかのデータをダウンロードすることです。そのアイデアは、タブが指す次のアクティビティがデータを使用してリストビューを作成することです。私は、タブのonClickListenerを使用しようとしてきましたが、動作していないようです。私はそれまでのことを付けています。ユーザーがTAB_NAME_2というラベルの付いたタブをクリックすると、performGetClasses()メソッドが呼び出されます。タブのヘルプOnClickListeners android

ありがとうございます。

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    try { 
     FileInputStream fis = openFileInput("token"); 
     try { 
     fis.read(tokenInt); 
     token = new String(tokenInt); 
     fis.close(); 
     } catch (IOException e) { 
     } 
    } catch (FileNotFoundException e) { 

    } 

    //TODO: Add code to send the token as a put extra to each tab, rather than retrieving in each separate activity. 

    setContentView(R.layout.home_screen); 

    Resources res = getResources(); 
    TabHost tabHost = getTabHost(); 
    TabHost.TabSpec spec; 
    Intent intent; 

    // Do the same for the other tabs 
    intent = new Intent().setClass(this, HomePage.class); 
    spec = tabHost.newTabSpec("TAB_NAME_1").setIndicator("Home",res.getDrawable(R.layout.ic_tab_home)).setContent(intent); 
    tabHost.addTab(spec); 


    intent = new Intent().setClass(this, ClassesPage.class); 
    spec = tabHost.newTabSpec("TAB_NAME_2").setIndicator("Classes",res.getDrawable(R.layout.ic_tab_classes)).setContent(intent); 
    tabHost.addTab(spec); 

    intent = new Intent().setClass(this, SearchPage.class); 
    spec = tabHost.newTabSpec("TAB_NAME_3").setIndicator("Search",res.getDrawable(R.layout.ic_tab_search)).setContent(intent); 
    tabHost.addTab(spec); 

    intent = new Intent().setClass(this, MessagesPage.class); 
    spec = tabHost.newTabSpec("TAB_NAME_4").setIndicator("Messages",res.getDrawable(R.layout.ic_tab_messages)).setContent(intent); 
    tabHost.addTab(spec); 

    intent = new Intent().setClass(this, AccountPage.class); 
    spec = tabHost.newTabSpec("TAB_NAME_5").setIndicator("Account",res.getDrawable(R.layout.ic_tab_account)).setContent(intent); 
    tabHost.addTab(spec); 

    tabHost.setCurrentTab(0); 
} 

public void performGetClasses(String token){ 

    progressDialog = ProgressDialog.show(HomeScreen.this, 
       "Please wait...", "Retrieving data...", true, true); 

     if (!(token == null)) { 
     PerformClassesTask task = new PerformClassesTask(); 
     task.execute(token); 
      progressDialog.setOnCancelListener(new CancelTaskOnCancelListener(task)); 
     } 
} 
+1

タブを使用しないでください。タブはすべて他のタブに依存するべきではありません。それはほぼ確実にあなたのデザインを再考する必要があることを意味します。 – Falmarri

+0

私のタブはお互いに依存していません。ユーザーがタブをクリックしてクラス画面に移動したときにダウンロードを実行したいだけです。私のタブはアクティビティを指しています。 –

答えて

0

あなたのクラスの意図をあなたのonCreateに入れてみませんか?

+0

ダウンロードを実行する非同期タスクがビューが描画される前に終了しないため、これを行うことはできません。私が間違っていない限り、ビュー自体が描画される前に、リストビューを作成するための情報を渡す必要があります。 –