tabhost的问题?

mydudu2005 2013-03-11 08:10:42
不使用tabActivity改用Activity出错了?求解?
调试执行到tabHost.addTab(tabSpec1);
错误信息:
Source not found.
求解?
源码如下:
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.RadioGroup;
import android.widget.TabHost;

public class MainActivity extends Activity{

private RadioGroup group;
private TabHost tabHost;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mytabhost);

tabHost = (TabHost) findViewById(R.id.mytabhost1);
tabHost.setup();
TabHost.TabSpec tabSpec1 = (TabHost.TabSpec)tabHost.newTabSpec("home").setIndicator("home");
tabSpec1.setContent(new Intent(MainActivity.this,webView.class));
tabHost.addTab(tabSpec1);
}
}


webView.class代码

public class webView extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
WebView webView=(WebView)findViewById(R.id.webView);
String strUrl="http://www.126.com";
webView.loadUrl(strUrl);

}
}

xml布局代码
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mytabhost1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
></FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="home"
android:text="@string/main_home"
/>
<RadioButton
android:id="@+id/rb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_home"
/>
<RadioButton
android:id="@+id/rb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_home"
/>
<RadioButton
android:id="@+id/rb4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_home"
/>
</RadioGroup>
</TabWidget>
</TabHost>
...全文
88 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

80,348

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧