getTabHost()在未定义的方法 [英] getTabHost() method in undefined
本文介绍了getTabHost()在未定义的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在做Android的标签。我使用TabHost实现这一目标。我正在下红线getTabHost()
在此行 TabHost tabHost = getTabHost()方法;
。我不知道为什么我得到这个。我怎样才能使这个例子工作?
下面是我的完整code
公共类TabActivity延伸活动{
// TabHost mTabHost;
/ **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main); 资源解析度= getResources(); //资源对象获取可绘制
TabHost tabHost = getTabHost(); //活动TabHost
TabHost.TabSpec规范; // Resusable则tabspec为每个标签
意图意图; //可重用的意图为每个标签 //艺术家标签
意图=新意图(这一点,Artist.class);
规格= tabHost.newTabSpec(艺术家)setIndicator(艺术家,res.getDrawable(R.drawable.tab_icon))setContent(意向)。
tabHost.addTab(规范); //歌曲
意图=新意图(这一点,Songs.class);
规格= tabHost.newTabSpec(诗经)setIndicator(诗经,res.getDrawable(R.drawable.tab_icon))setContent(意向)。
tabHost.addTab(规范); //相册
意图=新意图(这一点,Album.class);
规格= tabHost.newTabSpec(艺术家)setIndicator(艺术家,res.getDrawable(R.drawable.tab_icon))setContent(意向)。
tabHost.addTab(规范); tabHost.setCurrentTab(1);
}
}
解决方案
您需要延长MyTabActivity不是简单的活动
尝试
公共类MyTabActivity扩展TabActivity
的这一翻译
公共类MyTabActivity扩展活动
I am making tabs in android. I am using TabHost to achieve this. I am getting red line under getTabHost()
method on this line TabHost tabHost = getTabHost();
. I am not sure why am I getting this. How can I make this example work?
Here is my complete code
public class TabActivity extends Activity {
//TabHost mTabHost;
/** 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
//Artist Tab
intent = new Intent(this, Artist.class);
spec = tabHost.newTabSpec("artists").setIndicator("Artist", res.getDrawable(R.drawable.tab_icon)).setContent(intent);
tabHost.addTab(spec);
//Songs
intent = new Intent(this, Songs.class);
spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.tab_icon)).setContent(intent);
tabHost.addTab(spec);
//Albums
intent = new Intent(this, Album.class);
spec = tabHost.newTabSpec("artists").setIndicator("Artist", res.getDrawable(R.drawable.tab_icon)).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(1);
}
}
解决方案
you need to extend MyTabActivity not simple activity try
public class MyTabActivity extends TabActivity
intead of
public class MyTabActivity extends Activity
这篇关于getTabHost()在未定义的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文