Rek*_*kar 1 android android-layout
我是Android和Java开发的新手,我正在关注Android Dev网站上的Tab Layout教程.我遇到了代码问题.只需使用一些复制面食魔法来确保我没有拼写错误,我已经插入了教程所需的所有代码.问题是getTabHost()是未定义的......以下是代码:
public class AHActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, EvoActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("evolution").setIndicator("Evolution")
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, physActivity.class);
spec = tabHost.newTabSpec("physics").setIndicator("Physics")
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
}
Run Code Online (Sandbox Code Playgroud)
您的活动应该扩展TabActivity而不是Activity.
public class AHActivity extends TabActivity {
Run Code Online (Sandbox Code Playgroud)
注意:最新版本中不推荐使用Tabactivitity,请考虑学习片段
| 归档时间: |
|
| 查看次数: |
8208 次 |
| 最近记录: |