加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

tabhost内容未显示,跟xml有关

发布时间:2020-12-16 06:29:54 所属栏目:百科 来源:网络整理
导读:activity如下: package com.mobileclient.activity; import com.mobileclient.app.Declare; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.widget.RadioGroup; import android.widget.RadioGr


activity如下:

package com.mobileclient.activity;


import com.mobileclient.app.Declare;


import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;


public class TeachSourceDetailActivity extends TabActivity implements OnCheckedChangeListener{
private String courseNumber;
private TabHost tabHost;


private RadioGroup radioGroup;


public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置标题
setTitle("手机客户端-课程信息详情");
setContentView(R.layout.source_detail_main);
Declare declare = (Declare) getApplicationContext();
String username = declare.getUserName();
if (username == null) {
setTitle("当前位置--课程信息列表");
} else {
setTitle("您好:" + username + " 当前位置---课程信息列表");
}
radioGroup=(RadioGroup)findViewById(R.id.radiogroup);
radioGroup.setOnCheckedChangeListener(this);
tabHost=(TabHost)findViewById(android.R.id.tabhost);
tabHost.setFocusable(true);
tabHost.setCurrentTab(0);
tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("introduce")
.setIndicator("Introduce")
.setContent(new Intent(this,IntroduceActivity.class)));
tabHost.addTab(tabHost.newTabSpec("chapter").
setIndicator("Chapter").
setContent(new Intent(this,ChapterActivity.class)));
tabHost.addTab(tabHost.newTabSpec("notes").
setIndicator("Notes").
setContent(new Intent(this,NotesActivity.class)));


}
@Override
public void onCheckedChanged(RadioGroup group,int checkedId) {
// TODO Auto-generated method stub
switch (checkedId) {
case R.id.radio_introduce:
this.tabHost.setCurrentTabByTag("introduce");
break;
case R.id.radio_chapter:
this.tabHost.setCurrentTabByTag("chapter");
break;
case R.id.radio_notes:
this.tabHost.setCurrentTabByTag("notes");
break;

}
}


}


tabhost界面:

<?xml version="1.0" encoding="utf-8"?>

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="0.0dip" android:layout_weight="1.0"/> <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.0" android:visibility="gone" /> <RadioGroup android:id="@+id/radiogroup" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:background="@drawable/bottombg" android:gravity="center_vertical" android:orientation="horizontal" > <RadioButton android:id="@+id/radio_introduce" android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/introduce" android:button="@null" android:layout_weight="1" android:checked="true" style="@style/rbt_bottom" android:text="@string/introduce"/> <RadioButton android:id="@+id/radio_chapter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/introduce" android:layout_weight="1" android:button="@null" style="@style/rbt_bottom" android:text="@string/chapter"/> <RadioButton android:id="@+id/radio_notes" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/introduce" android:layout_weight="1" android:button="@null" style="@style/rbt_bottom" android:text="@string/notes" /> </RadioGroup> </LinearLayout> </TabHost>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读