вот шаблон xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/myviewHeader"
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
</TextView>
<LinearLayout
android:id="@+id/myviewIncluder"
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
</LinearLayout>
<TextView
android:id="@+id/myviewFooter"
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
</TextView>
</LinearLayout>
и класс для ViewGroup с динамическим содержимым
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MyView extends ViewGroup {
private LayoutInflater mInflater;
private TextView header;
private TextView footer;
public MyView(Context context,View child) {
super(context);
mInflater = LayoutInflater.from(context);
mInflater.inflate(R.layout.myview, this);
LinearLayout includer = (LinearLayout) findViewById(R.id.myviewIncluder);
header = (TextView) findViewById(R.id.myviewHeader);
footer = (TextView) findViewById(R.id.myviewFooter);
includer.addView(child);
}
@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) {
// TODO Auto-generated method stub
}
public void set_HeaderText(String text){
header.setText(text);
}
public void set_FooterText(String text){
footer.setText(text);
}
}
Если вы хотите добавить соперника в часть Includer, yozu может действовать следующим образом:
View include = null;
LayoutInflater mInflater = LayoutInflater.from(this);
include = mInflater.inflate(R.xml.list_item_icon_text,null);
ViewGroup text = new MyView(this,include);