@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
LinearLayout linear=(LinearLayout)inflater.inflate(R.layout.main_xml,null);
tabhost=(TabHost)linear.findViewById(R.id.detail_goods_tab);
tabhost.setup(this.getLocalActivityManager());
getTabHost();
main_tab_container.removeAllViews();
main_tab_container.addView(linear);
}
其中 tabhost.setup(this.getLocalActivityManager());这一行报空指针异常。请问一下这是什么回事?急,谢谢哪位了,我找了查了一天都没有查到结果,
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
LinearLayout linear=(LinearLayout)inflater.inflate(R.layout.main_xml,null);
tabhost=(TabHost)linear.findViewById(R.id.detail_goods_tab);
tabhost.setup(this.getLocalActivityManager());
getTabHost();
main_tab_container.removeAllViews();
main_tab_container.addView(linear);
}
其中 tabhost.setup(this.getLocalActivityManager());这一行报空指针异常。请问一下这是什么回事?急,谢谢哪位了,我找了查了一天都没有查到结果,
解决方案 »
- 快崩溃了,android调用带参数的.net web service 问题
- 高人请进!!
- android 开机自动启动自己写的shell,怎么配置?
- android仿iphone手指从屏幕下方向上滑动进入任务栏,图标全变灰色特效是如何实现
- SMS Inbox中的person的值的疑问
- contentprovider的安全互斥机制如何保证
- android蓝牙对战游戏,代码出错
- url对象与httpurlconnection对象分别是什么
- eclipse AVD启动问题
- 关于 Application 中的 onCreate 好像没有被执行
- git使用中发生的错误
- 还是那个蛋疼的问题,J2EE和Andorid,向左走向右走?
TabHost tabhost ;
TabWidget tabWidget;
TextView all_evaluate, good_evaluate,mid_evaluate,bad_evaluate;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
LinearLayout linear=(LinearLayout)inflater.inflate(R.layout.main_xml,null);
tabhost=(TabHost)linear.findViewById(R.id.detail_goods_tab);
tabhost.setup(this.getLocalActivityManager());
getTabHost();
main_tab_container.removeAllViews();
main_tab_container.addView(linear);
}
public void getTabHost(){
tabhost.addTab(tabhost.newTabSpec("introduce")
.setIndicator("全部评论")
.setContent(new Intent(this,All_Evaluate_View.class)));
tabhost.addTab(tabhost.newTabSpec("specification")
.setIndicator("好评1344")
.setContent(new Intent(this,Good_Evaluate_View.class)));
tabhost.addTab(tabhost.newTabSpec("pacagelist")
.setIndicator("中评101")
.setContent(new Intent(this,Mid_Evaluate_View.class)));
tabhost.addTab(tabhost.newTabSpec("aftersale")
.setIndicator("差评30")
.setContent(new Intent(this,Bad_Evaluate_View.class)));
tabhost.setCurrentTab(0);
tabWidget=tabhost.getTabWidget();
set_tabWidget();
}
public void set_tabWidget(){ int height=50;
int width=getWindowManager().getDefaultDisplay().getWidth()/4;
for (int i =0; i < tabWidget.getChildCount(); i++)
{
/**
* 设置高度、宽度,不过宽度由于设置为fill_parent,在此对它没效果
*/
tabWidget.getChildAt(i).getLayoutParams().height = height;
tabWidget.getChildAt(i).getLayoutParams().width = width;
/**
* 设置tab中默认标题文字的颜色,不然默认为黑色
*/
if(i==0){
TextView tv1 = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
/*SpannableStringBuilder style=new SpannableStringBuilder(tv1.getText());
style.setSpan(new ForegroundColorSpan(Color.RED),0,2,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv1.setText(style);*/
tv1.setTextColor(Color.BLACK);
tv1.setTextSize(12);
tv1.setPadding(15, 5, 15, 8);
}else{
TextView tv1 = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
int tv_leng=tv1.getText().toString().length();
SpannableStringBuilder style=new SpannableStringBuilder(tv1.getText());
style.setSpan(new ForegroundColorSpan(Color.RED),2,tv_leng,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv1.setText(style);
tv1.setTextColor(Color.BLACK);
tv1.setTextSize(12);
tv1.setPadding(15, 5, 15, 8);
}
View vvv = tabWidget.getChildAt(i);
//如果是当前选中的tab 设置其背景颜色
if(tabhost.getCurrentTab()==i){
vvv.setBackgroundResource(R.drawable.tab_state1);
}
else {
vvv.setBackgroundResource(R.drawable.tab_state2);
}
}
这是我代码,请lingang1359你帮我看看吧,谢谢了