2010-11-23 19 views
2

我有一個帶有2個選項卡的選項卡式佈局,每個選項卡都有它自己的視圖。我搜索一個可以被覆蓋的函數,每當我點擊一個選項卡來顯示佈局時,就會調用這個函數。Android中是否有像MFC中的onShow一樣的佈局功能

在此先感謝...

哈桑Caliskan

編輯:

感謝您的答案,但它不工作...

onWindowVisibilityChanged 

被稱爲一個如果我開始我的應用程序。

onFocusChanged 

功能從來沒有被稱爲?

或者我做錯了什麼? 下面是代碼我實現......

protected void onWindowVisibilityChanged(int a) 
{ 
    int c = 0; 

    c+= 1; 
} 

protected void onFocusChanged(boolean b, int i , Rect rec) 
{ 
    int c = 0; 

    c += 1; 
} 
+0

嗨, 我希望你有兩個標籤,即主,副,當你cliked主選項卡,視圖必須是開放的,同樣,當你clikced子選項卡,另一種觀點必須打開。我的權利 – 2010-11-23 11:17:18

+0

是的,這就是我試圖展示佈局的方式。 – 2010-11-23 12:01:00

回答

1
  Then you can use tabchanged event as shown below 

tabHost.addTab(tabHost.newTabSpec("tab1").setContent(
       R.id.content_movies).setIndicator("", 
       getResources().getDrawable(R.drawable.menu_article))); 
     tabHost.addTab(tabHost.newTabSpec("tab2").setContent(
       new Intent(this, BS_Bars.class)).setIndicator("", 
       getResources().getDrawable(R.drawable.menu_bar))); 
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { 

     @Override 
     public void onTabChanged(String arg0) { 
     Bundle b=new Bundle(); 

     if(arg0.equals("tab1")) 
     { 

     // write the code here to show the view 


     } 

     else if (arg0.equals("tab2")) { 

       // write the code here to show the view 
     } 
     }); 
0

如何重寫

onWindowFocusChanged(boolean hasWindowFocus) 

含有這種觀點得到或失去焦點,當窗口調用。

編輯:嘗試

onFocusChanged(boolean, int, Rect) or onWindowVisibilityChanged(int) 
+0

嗨,我曾試過這個,但功能不會調用,如果我切換標籤。這個功能只有在我離開我的應用時纔會被調用。 MFC中沒有像onShow這樣的函數嗎? – 2010-11-23 12:00:17

相關問題