| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2029 人关注过本帖
标题:关于TabHost的问题
只看楼主 加入收藏
wkz2012
Rank: 4
等 级:业余侠客
帖 子:123
专家分:253
注 册:2012-12-13
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
关于TabHost的问题
想做一个简单的标签页,即TabHost,可编译完后,运行模拟器时,总是出现如下的情况。(我用的版本时2.3.3,开发工具是ADT)
图片附件: 游客没有浏览图片的权限,请 登录注册

下面是我的activity_main.xml文件


程序代码:
<?xml version="1.0"  encoding="utf-8"?>
  <TabHost  xmlns:android="http://schemas. android:id="@android:id/tabhost"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" 
    >
    <LinearLayout
        xmlns:android="http://schemas. android:id="@+id/textView1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/text1" />
    </LinearLayout>
   
     <LinearLayout
        android:id="@+id/tab2"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
       <TextView
                android:id="@+id/textView2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/text2"/>
    </LinearLayout>
</TabHost>




下面则是Mainfest.xml文件
 
   <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas. package="com.example.stone"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="10" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.stone.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
下面是java主程序


程序代码:
package com.example.stone;

import android.os.Bundle;
//import android.app.Activity;
import android.app.TabActivity;
//import android.content.Intent;
//import android.view.Menu;
import android.view.LayoutInflater;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.Toast;

public class MainActivity extends TabActivity {

    private TabHost mTabHost;
    //private Adapter1 ad1;   
    //private ListView ListView1;    
    //private Intent mIntent;
   
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        //ad1 = new Adapter1(MainActivity.this,4);
        //mIntent = new Intent();
        TabHost tabHost = this.getTabHost();
        LayoutInflater.from(this).inflate(R.layout.activity_main, mTabHost.getTabContentView(), true);

         tabHost.addTab(tabHost.newTabSpec("1")   
                        .setIndicator("OneTab",null)   
                        .setContent(R.id.tab1));
       

         tabHost.addTab(tabHost.newTabSpec("2")   
                      .setIndicator("TwoTab",null)   
                      .setContent(R.id.tab2));
         mTabHost.setOnTabChangedListener(new OnTabChangeListener(){
             public void onTabChanged(String tabId){
                 
                if(tabId == "1"){
                     DisplayToast("Tab1");
                 }
                else{
                    DisplayToast("Tab2");
                }
             }
            
         });




    }


    protected void DisplayToast(String s) {
        // TODO Auto-generated method stub
        Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show();
    }

    /*@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
*/
}
2013-04-13 21:26
wkz2012
Rank: 4
等 级:业余侠客
帖 子:123
专家分:253
注 册:2012-12-13
收藏
得分:0 
补充一下,R。java文件时没问题的,编译没有错误,就是运行模拟器出现图中的情况。麻烦大神们了

我了个去的编程!
2013-04-13 21:27
huang798_186
Rank: 2
等 级:论坛游民
帖 子:2
专家分:20
注 册:2013-4-14
收藏
得分:20 
注册否??
2013-04-14 10:17
wkz2012
Rank: 4
等 级:业余侠客
帖 子:123
专家分:253
注 册:2012-12-13
收藏
得分:0 
回复 3楼 huang798_186
你问的是软件的注册吗?

我了个去的编程!
2013-04-14 17:26
见面say_hi
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-9-10
收藏
得分:0 
应该是TabHost的配置文件错误吧,你可以参照下面的:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.
     android:id="@android:id/tabhost"
     android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentBottom="true"
            
            ></TabWidget>
        
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@android:id/tabs"
            />
    </RelativeLayout>
   
    </TabHost>
2014-09-16 11:18
快速回复:关于TabHost的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026968 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved