选项卡的小问题

Android 码拜 9年前 (2015-09-30) 948次浏览

为啥一tabhost.setup();就崩了?

package com.example.tabhost;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.TabHost;

public class MainActivity extends Activity {
	private TabHost tabhost;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.i("14", "start");
		setContentView(R.layout.activity_main);
		Log.i("15", "start");
		tabhost = (TabHost)findViewById(R.id.tabhost);
		Log.i("17", "start");
//		为啥一运行到这就崩了?
		tabhost.setup();//初始化
		Log.i("20", "start");
		LayoutInflater inflater = LayoutInflater.from(this);//实例化
		Log.i("21", "start");
		inflater.inflate(R.layout.first, tabhost.getTabContentView());
		inflater.inflate(R.layout.second, tabhost.getTabContentView());
		inflater.inflate(R.layout.third, tabhost.getTabContentView());
		Log.i("25", "start");
		tabhost.addTab(tabhost.newTabSpec("tab01")
				.setIndicator("第一个tab")
				.setContent(R.id.tab01));
		tabhost.addTab(tabhost.newTabSpec("tab02")
				.setIndicator("第二个tab")
				.setContent(R.id.tab02));
		tabhost.addTab(tabhost.newTabSpec("tab03")
				.setIndicator("第三个tab")
				.setContent(R.id.tab03));
		Log.i("27", "start");
	}
}
解决方案:20分
贴错误信息,报的是空,还是什么。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明选项卡的小问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)