2012-08-08 61 views
0

我是這裏的新人和剛剛創建我的Android應用程序的多標籤界面,但是當我嘗試在多個標籤屏幕之一,按壓沒有動,我創建另一個畫面時,該按鈕創建一個按鈕。我在想,如果我需要在我的多標籤屏幕中添加任何代碼,以使該按鈕的作品。這是我爲我的多標籤java代碼:爲什麼我的按鈕不移動到另一個屏幕?

public class Investment extends TabActivity { 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_investment); 

    TabHost tabHost = getTabHost(); 

    // Tab for Homepage 
    TabSpec photospec = tabHost.newTabSpec("Home"); 
    // setting Title and Icon for the Tab 
    photospec.setIndicator("Home", getResources().getDrawable(R.drawable.homeicon)); 
    Intent photosIntent = new Intent(this, Home.class); 
    photospec.setContent(photosIntent); 

    // Tab for Riskassessment 
    TabSpec songspec = tabHost.newTabSpec("Risk"); 
    songspec.setIndicator("Risk", getResources().getDrawable(R.drawable.riskicon)); 
    Intent songsIntent = new Intent(this, RiskAssessment.class); 
    songspec.setContent(songsIntent); 

    // Tab for News 
    TabSpec videospec = tabHost.newTabSpec("News"); 
    videospec.setIndicator("News", getResources().getDrawable(R.drawable.newsicon)); 
    Intent videosIntent = new Intent(this, News.class); 
    videospec.setContent(videosIntent); 

// Tab for Tips 
    TabSpec tipsspec = tabHost.newTabSpec("Tips"); 
    tipsspec.setIndicator("Tips", getResources().getDrawable(R.drawable.investmenttipsicon)); 
    Intent tipsIntent = new Intent(this, InvestmentTips.class); 
    tipsspec.setContent(tipsIntent); 

// Tab for about us 
    TabSpec aboutusspec = tabHost.newTabSpec("About Us"); 
    aboutusspec.setIndicator("About Us", getResources().getDrawable(R.drawable.aboutusicon)); 
    Intent aboutusIntent = new Intent(this, AboutUs.class); 
    aboutusspec.setContent(aboutusIntent); 

    // Adding all TabSpec to TabHost 
    tabHost.addTab(photospec); // Adding tab 
    tabHost.addTab(songspec); 
    tabHost.addTab(videospec); 
    tabHost.addTab(tipsspec); 
    tabHost.addTab(aboutusspec); 

} 

代碼爲我的按鈕

public class ButtonSelection extends Activity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.home); 

    Button b = (Button) findViewById(R.id.buttonequity); 
    b.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View arg0) { 
     Intent i = new Intent(ButtonSelection.this, EquitySelection.class); 
     startActivity(i); 
     } 
    }); 
    } 
    } 

代碼屏幕當我按下按鈕

public class EquitySelection extends Activity { 

@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.equitydescription); 
    } 
    } 
+0

您是否在您的menifest文件中爲類 – Akshay 2012-08-08 16:48:04

+0

添加了權限,請參閱我在TabHost中更改活動的答案。 – 2012-08-08 16:55:48

回答

0

後與爭奪的很長一段時間這個問題我已經能夠找到一個解決方案,以使用基於活動標籤時切換標籤。

在其中tabhost創建我實現類似下面的方法中的父活動類:

public void switchTab(int tab){ 
     tabHost.setCurrentTab(tab); 

}

內部的標籤的,我想是能夠內部切換到另一個選項卡我創建下面的方法:

public void switchTabInActivity(int indexTabToSwitchTo){ 
     MintTrack ParentActivity; 
     ParentActivity = (MintTrack) this.getParent(); 
     ParentActivity.switchTab(indexTabToSwitchTo); 

}

另請參閱:Example

+0

也看到這個例子http://stackoverflow.com/questions/3871681/android-how-to-change-activity-within-a-tab – 2012-08-08 16:56:28

相關問題