Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:从TabHost继承,例如使用TabHost而不使用活动_Android_Xamarin.android_Android Tabhost - Fatal编程技术网

Android:从TabHost继承,例如使用TabHost而不使用活动

Android:从TabHost继承,例如使用TabHost而不使用活动,android,xamarin.android,android-tabhost,Android,Xamarin.android,Android Tabhost,我想在现有的TabHost/TabActivity中使用TabHost。所以我想去掉Activity类,只实现一个继承自TabHost的viewgroup类。但是,如果没有相应的Activity类,就不可能使用TabHost—在显示扩展类时,TabHost及其内容不会显示出来 我使用了TabHost类并添加了线性布局,其中包含选项卡和内容容器,以及来自xml的适当id(android:id/tabs和android:id/tabcontent) public class EmitterView

我想在现有的TabHost/TabActivity中使用TabHost。所以我想去掉Activity类,只实现一个继承自TabHost的viewgroup类。但是,如果没有相应的Activity类,就不可能使用TabHost—在显示扩展类时,TabHost及其内容不会显示出来

我使用了TabHost类并添加了线性布局,其中包含选项卡和内容容器,以及来自xml的适当id(android:id/tabs和android:id/tabcontent)

public class EmitterView : TabHost, TabHost.ITabContentFactory
{
public EmitterView(Context context) :
base(context)
{
Initialize();
}

public EmitterView(Context context, IAttributeSet attrs) :
base(context, attrs)
{
Initialize();
}

private void Initialize()
{
// construct the TAB Host

LayoutInflater inflater = (LayoutInflater)    
this.Context.GetSystemService(Context.LayoutInflaterService);
View view = inflater.Inflate(AndroidFilterEditor.Resource.Layout.EmitterTabHost, null);
this.AddView(view);

this.Setup();

// Create Tabs
TabSpec emitter = this.NewTabSpec("Emitter");
emitter.SetIndicator("Emitter", Resources.GetDrawable(AndroidFilterEditor.Resource.Drawable.ic_tab_artists));
//Intent emitterIntent = new Intent(this.Context, typeof(EmitterActivity));
emitter.SetContent(this);
this.AddTab(emitter);
this.Invalidate();
}

public View CreateTabContent(string tag)
{
EmitterContentView view = new EmitterContentView(this.Context);
return view;
}
}
布局定义:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>


你知道这是否可能吗?顺便说一句,这是Android的Mono,因此代码显然是C语言。

您可以使用ActivityGroup在其中托管多个活动,并为每个活动分配tabhost。尽管它变得复杂,而且不受鼓励。我建议您在另一个tabhost中使用片段而不是tabhost。

我现在用按钮而不是真正的选项卡构建了自己的选项卡栏,因为解决方案更干净。仍然想知道为什么安卓系统嵌套标签会有这样的问题。