2012-03-22 9 views
0

私のアプリケーションの構造は次のとおりです。メインアクティビティには4つのタブ(アカウント、ダッシュボード、メディア、アプリケーション)があります。各タブはアクティビティにリンクされています。アプリケーションタブには多くのアクティビティが含まれており、タブを表示するために、私のApplicationsActivityでif/elseを実行して表示する必要があります(おそらくこれを実行する最良の方法ではありませんが、 )。アクティビティをTabLayoutにキャッシュしないでください

私の問題:[アプリケーション]タブに移動すると、すべてのアプリケーションの一覧が表示されます.1つのアプリケーションをクリックすると、このアプリケーションのオプションが表示された新しい画面が表示されます。新しい画面など 次に[Medias]タブをクリックすると、すべてのMediasのリストが表示されます。 次に、[アプリケーション]タブをもう一度クリックします。画面上には、特定のアプリケーションのオプションが表示されます。 私が欲しいのは、すべてのアプリケーションのリストに戻ってくることです。

どうすればいいですか?どのようにして、タブにアクティビティをリロードしてキャッシュのように見せてはいけないと伝えることができますか? /他のバンドル内の値上が)(setContentViewで使用するためにどのようなレイアウトを知っている場合、私はちょうど私のやるApplicationsActivityで

public class MainActivity extends TabActivity { 
private int currentTab = 1; 
private Application application = null; 
private String optionType = null; 
private String checkID = null; 
private String alertID = null; 
private int periodID = -1; 
private Statistic stat = null; 
private Media media = null; 
TabHost tabHost; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.main); 

    PreferencesManager.load(this); 

    Bundle bundle = getIntent().getExtras(); 
    if (bundle != null) { 
     Log.i("IV", bundle.toString()); 

     String applicationID = null; 
     applicationID = bundle.getString("applicationID"); 
     if (applicationID != null) { 
      try { 
       this.application = Utils.getApplication(applicationID); 
      } catch (AuthenticationFailedException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (ApiCallErrorException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (InternalErrorException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } else { 
      this.application = (Application) bundle 
        .getSerializable("application"); 
     } 

     this.currentTab = bundle.getInt("currentTab", 1); 
     this.optionType = bundle.getString("optionType"); 
     this.checkID = bundle.getString("checkID"); 
     this.alertID = bundle.getString("alertID"); 
     this.periodID = bundle.getInt("periodID", -1); 
     this.stat = (Statistic) bundle.getSerializable("stat"); 
     this.media = (Media) bundle.getSerializable("media"); 
    } 

    Log.i("IV", "current tab : " + currentTab); 

    Resources res = getResources(); // Resource object to get Drawables 
    tabHost = getTabHost(); // The activity TabHost 

    tabHost.setOnTabChangedListener(new OnTabChangeListener() { 

     public void onTabChanged(String tabId) { 
      //Log.i("IV", "Tab id : " +tabId); 
      setTabColor(); 
     } 
    }); 

    TabHost.TabSpec spec; // Resusable TabSpec for each tab 

    // Create an Intent to launch an Activity for the tab (to be reused) 
    Intent intent = new Intent().setClass(this, AccountActivity.class); 

    // Initialize a TabSpec for each tab and add it to the TabHost 
    spec = tabHost 
      .newTabSpec("account") 
      .setIndicator(getString(R.string.account), 
        res.getDrawable(R.drawable.tab_account)) 
      .setContent(intent); 
    tabHost.addTab(spec); 

    // Do the same for the other tabs 
    intent = new Intent().setClass(this, DashboardActivity.class); 
    spec = tabHost 
      .newTabSpec("dashboard") 
      .setIndicator(getString(R.string.dashboard), 
        res.getDrawable(R.drawable.tab_dashboard)) 
      .setContent(intent); 
    tabHost.addTab(spec); 

    intent = new Intent().setClass(this, MediasActivity.class).putExtra(
      "media", media); 
    spec = tabHost 
      .newTabSpec("medias") 
      .setIndicator(getString(R.string.medias), 
        res.getDrawable(R.drawable.tab_media)) 
      .setContent(intent); 
    tabHost.addTab(spec); 

    intent = new Intent().setClass(this, ApplicationsActivity.class) 
      .putExtra("application", application) 
      .putExtra("optionType", optionType) 
      .putExtra("checkID", checkID).putExtra("alertID", alertID) 
      .putExtra("periodID", periodID).putExtra("stat", stat); 
    spec = tabHost 
      .newTabSpec("applications") 
      .setIndicator(getString(R.string.applications), 
        res.getDrawable(R.drawable.tab_application)) 
      .setContent(intent); 
    tabHost.addTab(spec); 

    setTabColor(); 

    if (!PreferencesManager.getBoolean("isLogged")) { 
     for (int i = 1; i < 4; i++) { 
      tabHost.getTabWidget().getChildTabViewAt(i).setEnabled(false); 
      tabHost.getTabWidget().getChildTabViewAt(i) 
        .setBackgroundColor(Color.rgb(102, 102, 102)); 
     } 
     tabHost.setCurrentTab(0); 
    } else { 
     tabHost.setCurrentTab(currentTab); 
    } 
} 

public void setTabColor() { 
    for(int i=0;i<this.tabHost.getTabWidget().getChildCount();i++) 
    { 
     this.tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#000000")); //unselected 
    } 
    this.tabHost.getTabWidget().getChildAt(this.tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#ABABAB")); // selected 
} 
} 

;:ここ

は私の主な活動コードです

ありがとうございました!

答えて

1

私ドン; tはあなたの問題を理解している場合は知っているが、多分あなたの活動の設定を変更し、追加のAndroidマニフェストファイルにしてみてください:

android:noHistory="true" 
+0

私はすでにこれを試みたが、私は戻るボタンが仕事をしたいです。とにかくありがとう。 – Hooli

0

は、あなたがこれまでのユーザーにあなたのTabActivity内部ActivityGroupを試みたことがありますか? ActivityGroupを使うと、if-else-thing全体を簡単に取り除くことができます。

これは実際にあなたの問題を解決するだろう: Going back to previous TabActivity

関連する問題