当前位置:编程学习 > wap >>

tabhost的问题?

不使用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>
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,