Java 为什么我的按钮不移动到另一个屏幕?

Java 为什么我的按钮不移动到另一个屏幕?,java,android,tabs,screen,Java,Android,Tabs,Screen,我是这里的新手,刚刚在我的android应用程序上创建了一个多选项卡屏幕,但当我尝试在多选项卡屏幕中的一个屏幕上创建按钮时,按下的按钮没有移动到我创建的另一个屏幕。我想知道我是否需要在我的多选项卡屏幕中添加任何代码以使按钮正常工作。以下是我的多重选项卡的java代码: public class Investment extends TabActivity { public void onCreate(Bundle savedInstanceState) { super.o

我是这里的新手,刚刚在我的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);
     }
     }

在与这个问题斗争了很长一段时间后,我终于找到了一个解决方案,可以在使用基于活动的选项卡时切换选项卡

在创建tabhost的父活动类中,我实现了如下方法:

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

在我希望能够在内部切换到另一个选项卡的选项卡内,我创建了以下方法:

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


另请参见此

您是否在menifest文件中添加了类的权限请参见TabHost中的“更改活动的我的答案”。另请参见此示例