I figured out it.
In my opinion, best way to do multiplayed component is to make it almost fully in Java code.
Solution presented below allows you to pass additional arguments in contructors of classes, but disadvantage is that you have to place everything with code which is not so convenient as using builder.
Now some sketch of how to do it:
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left|bottom" >
<!-- SOME STUFF WHICH IS NOT IMPORTANT -->
</LinearLayout>
<RelativeLayout
android:id="@+id/resultOutputLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- HERE WILL BE SHOWNED COMPONENTS ADDED IN JAVA CODE (LOOK INTO CLASSES PRESENTED BELOW) -->
</RelativeLayout>
</LinearLayout>
CLASSES:
This class contains panel with multiplayed components:
public class MainActivity extends Activity
{
private PanelWithMultipliedComponents;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_icd_search);
initGUI();
}
private void initGUI()
{
RelativeLayout resultOutputLayout = (RelativeLayout) findViewById(R.id.resultOutputLayout);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// adding a panel which contains an multiplied elements
final int LANG_SEL_PAN_ID = 666; //may be usefull later
langSelPanel = new PanelWithMultipliedComponents(this, null);
langSelPanel.setId(LANG_SEL_PAN_ID);
params.addRule(RelativeLayout.CENTER_VERTICAL);
langSelPanel.setLayoutParams(params);
resultOutputLayout.addView(langSelPanel);
}
}
This class is a panel with multiplayed components:
public class PanelWithMultipliedComponents extends LinearLayout
{
private Paint innerPaint;
private Context mainActivity; //this is MainActivity in fact
public PanelWithMultipliedComponents (Context context)
{
super(context);
initGUI(context);
}
public PanelWithMultipliedComponents (Context context, AttributeSet attrs)
{
super(context, attrs);
initGUI(context);
VersionManager.lockLanguages(languageSelectors);
}
private void initGUI(Context context)
{
mainActivity= context; // you can cast it later to use methods of MainActivity
setOrientation(VERTICAL);
multiplyComponents(Context context);
}
private void multiplyComponents(Context context)
{
MultipliedComponent[] comp= { new MultipliedComponent(context, null, this), new MultipliedComponent(context, null, this), new MultipliedComponent(context, null, this), new MultipliedComponent(context, null, this)};
for (int i = 0; i < comp.length; i++)
{
addView(comp[i]);
languageSelectors.add(comp[i]);
}
}
}
This class is a multiplayed component (which contains check box and some picture):
public class MultipliedComponent extends LinearLayout
{
private PanelWithMultipliedComponents container;
private ImageView somePicture;
private CheckBox someCheck;
public MultipliedComponent(Context context, AttributeSet att)
{
super(context, att);
}
public MultipliedComponent(Context context, AttributeSet att, PanelWithMultipliedComponents container)
{
this(context, att);
this.container = container;
initGUI(context);
}
public void initGUI(Context context)
{
setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
setGravity(Gravity.CENTER_VERTICAL);
someCheck= new CheckBox(context);
langSelection.setChecked(true); // or false
addView(someCheck);
somePicture= new ImageView(context);
try
{
Bitmap bitmap = BitmapFactory.decodeStream(/**get your assets manager somehow - eg. throug static reference to you application**/);
somePicture.setScaleType(ScaleType.FIT_CENTER);
somePicture.setImageBitmap(bitmap);
somePicture.setPadding(0, 0, 10, 0);
}
catch (IOException e)
{
Log.e("IMAGE_OPEN_EXC", e.toString());
}
addView(somePicture);
}
}