在android中以编程方式将复合视图类添加到视图中

在android中以编程方式将复合视图类添加到视图中,android,android-layout,composite-component,Android,Android Layout,Composite Component,您好,我正在尝试以编程方式将复合视图类添加到视图中。但我不知道怎么做。 我可以直接将它添加到布局中,这很好 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainLlt" android:layout_width="match_parent" android:layou

您好,我正在尝试以编程方式将复合视图类添加到视图中。但我不知道怎么做。 我可以直接将它添加到布局中,这很好

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLlt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<com.example.androidcustomvliveapplication.widget.CustomCardSection 
    android:id="@+id/cardSection2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
</com.example.androidcustomvliveapplication.widget.CustomCardSection> 
</LinearLayout>

你能帮我把客户卡的代码贴出来吗?好的,我会更新我的问题。你找到解决办法了吗?你能帮帮我吗?
public class CustomCardSection extends RelativeLayout
{

int section;

@SuppressLint("NewApi")
public CustomCardSection(Context context, AttributeSet attrs,
        int defStyleAttr, int defStyleRes)
{
    super(context, attrs, defStyleAttr, defStyleRes);
}

public CustomCardSection(Context context, AttributeSet attrs,
        int defStyleAttr) 
{
    super(context, attrs, defStyleAttr);
}

public CustomCardSection(Context context, AttributeSet attrs)
{
    super(context, attrs);

     LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     inflater.inflate(R.layout.custom_card_section, this, true);
    }

public CustomCardSection(Context context) 
{
    super(context);
}
}