Here is the xml template
<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>
and class for dynamic content view group
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) {
If you want to add vie to the Includer part, yozu can act as follows:
View include = null; LayoutInflater mInflater = LayoutInflater.from(this); include = mInflater.inflate(R.xml.list_item_icon_text,null); ViewGroup text = new MyView(this,include);
source share