java.lang.IllegalArgumentException: you must specify a way to create the tab content

今天遇到了这个问题

java.lang.IllegalArgumentException: you must specify a way to create the tab content



解决办法:


 
TabHost tab_host = null;
LayoutInflater inflater = null;

@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

initTabsView();
}
    
@SuppressWarnings("deprecation")
public void initTabsView(){

Intent intent = new Intent(this,PersonActivity.class);//添加intent

inflater = LayoutInflater.from(this);
tab_host = this.getTabHost();

for(int i =0;i<4;i++){

TabSpec tab_spec = tab_host.newTabSpec(ConValue.tab_text_info[i]);
tab_spec.setIndicator(getTabView(i));
tab_spec.setContent(intent);//根据tab content 来判断你是否添加了setContent
tab_host.addTab(tab_spec);

}


}

public View getTabView(int i){
View view = inflater.inflate(R.layout.tab_layout_info,null);
ImageView image = (ImageView)view.findViewById(R.id.tab_image);

image.setImageResource(R.drawable.user);

TextView text = (TextView)view.findViewById(R.id.tab_text);
text.setText(ConValue.tab_text_info[i]);

return view;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值