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