Android 扩展视图组

Android 扩展视图组,android,android-layout,Android,Android Layout,在活动中,在onCreate(…)中,我写道 SomeClass扩展了LinearLayout,一些带有按钮的布局是正确的 但在模拟器的显示器上——什么也没有。为什么? UPD: 我想你的构造函数代码中缺少了一些对的调用你调用了super.onCreate()?是的,当然,我调用了super.onCreate(…)我不明白,你是在告诉我应该在某个类构造函数中调用addView(…)什么吗?为什么?我在xml文件中添加了所有必要的元素。这两个视图(textview和button)是如何将它们的父

在活动中,在onCreate(…)中,我写道

SomeClass扩展了LinearLayout,一些带有按钮的布局是正确的 但在模拟器的显示器上——什么也没有。为什么?

UPD:



我想你的构造函数代码中缺少了一些对的调用

你调用了
super.onCreate()
?是的,当然,我调用了super.onCreate(…)我不明白,你是在告诉我应该在某个类构造函数中调用addView(…)什么吗?为什么?我在xml文件中添加了所有必要的元素。这两个视图(textview和button)是如何将它们的父视图设置为您的SomeClass实例的?好的,我创建了xml文件(添加到问题中),在我将此布局添加到视图(SomeClass)后,我现在应该做什么?让我看看我是否得到了您想要的。您是否正在尝试将发布的XML内容链接到SomeClass?如果是这种情况,则将XML中最外层的元素从LienearLayout更改为your.package.SomeClass(保留其他参数),将其添加为“android:id”参数(比如“someId”),并在活动的onCreate中调用setContentView(findViewById(R.layout.someId))-用记忆写的。现在去吃饭吗
public SomeClass(Context context, SomeType some_arg) {
         super(context);
         LayoutInflater inflater = (LayoutInflater)context.getSystemService(
                  Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.some_layout_with_button, this, true);
        m_button=(Button)findViewById(R.id.mButton);
        m_textView=(TextView)findViewById(R.id.mTextView);
        m_button.setOnClickListener(new OnClickListener(){
                @Override
                public void onClick(View v){
                //TODO
                }
            });
    }
this.setContentView(new SomeClass(getApplicationContext(),arg));
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    <LinearLayout android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="20px">
        <Button android:id="@+id/mButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="BT" />
        <TextView android:id="@+id/mTextView"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textSize="16px"
                />
    </LinearLayout>
    <LinearLayout android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
        <RadioGroup android:id="@+id/mRadioGroup"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
            <RadioButton android:id="@+id/mRadioButton1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="60px"
                    android:text="Text1"/>
            <RadioButton android:id="@+id/mRadioButton2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="60px"
                    android:text="Text2"/>
        </RadioGroup>
    </LinearLayout>
</LinearLayout>