Note that there are some explanatory texts on larger screens.

plurals
  1. POcustom LinearLayout with custom View elements shows nothing
    primarykey
    data
    text
    <p>I have a class <code>CustomView</code> which extends <code>LinearLayout</code>. I have another class <code>CustomElement</code> which also extends <code>LinearLayout</code>. When i try to use my class in XML nothing shows up.</p> <p>This is my class CustomView:</p> <pre><code>private static int NUMBER_OF_ELEMENTS = 4; public CustomView(final Context context, AttributeSet attrs) { super(context, attrs); init(context); } private void init(Context context) { // get size for each element int width = getWidth() / NUMBER_OF_ELEMENTS; int height = getHeight() / NUMBER_OF_ELEMENTS; for (int i = 0; i &lt; NUMBER_OF_ELEMENTS; i++) { CustomElement element = new CustomElement(context); addView(element, width, height); } } </code></pre> <p>This is my class CustomElement:</p> <pre><code>public CustomElement(final Context context) { super(context); m_context = context; init(context); } private void init(Context context) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.custom_elem, this); } </code></pre> <p>When i now try to add my <code>CustomView</code> in XML it doesn't show anything. Here is my XML Code:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_mainleft" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;com.package.views.CustomView android:id="@+id/layout_elements" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Am I missing something? Any help is appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload