내용을 요약해보면 Tab을 하나의 뷰클래스 안에 넣어서 사용하고싶습니다
생각으로 될것 같은데 nullPointException 이 발생합니다
소스코드는 다음과 같구요
public class TestTabActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
// TabHost tab = (TabHost)findViewById(R.id.tabhost);
// tab.setup();
//
// TextView textView5 = new TextView(this);
// textView5.setText("일반정보");
// TextView textView6 = new TextView(this);
// textView6.setText("갤러리");
//
// tab.addTab(tab.newTabSpec("tab1").setIndicator(textView5).setContent(R.id.button));
// tab.addTab(tab.newTabSpec("tab2").setIndicator(textView6).setContent(R.id.button1));
Tab c = new Tab(this);
setContentView(c);
}
}
class Tab extends LinearLayout {
public Tab(Context context) {
super(context);
// TODO Auto-generated constructor stub
TabHost tab = (TabHost)findViewById(R.id.tabhost);
tab.setup();
TextView textView5 = new TextView(getContext());
textView5.setText("일반정보");
TextView textView6 = new TextView(getContext());
textView6.setText("갤러리");
tab.addTab(tab.newTabSpec("tab1").setIndicator(textView5).setContent(R.id.button));
tab.addTab(tab.newTabSpec("tab2").setIndicator(textView6).setContent(R.id.button1));
LayoutInflater inflaer = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout linear = (LinearLayout)inflaer.inflate(R.layout.main, null);
addView(linear);
}
}
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/linear">
<Button
android:id="@+id/button"
android:text="111111"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/linear1">
<Button
android:id="@+id/button1"
android:text="22222222"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
에러 내용은 첨부했습니다
꼭좀도와주세요~~