Note that there are some explanatory texts on larger screens.

plurals
  1. POBuild Custom View with allways same Layout
    primarykey
    data
    text
    <p>I have made my own layout for a Button. Normaly I create a View by this:</p> <pre><code>LayoutInflater inflater = LayoutInflater.from(getActivity()); myButton = inflater.inflate(R.layout.mybutton, null, false); </code></pre> <p>Now my idea is that the Class myButton extends View and I do not have to write these lines for each Button. But how can I bring these two lines in myButton Constructor? I can't write:</p> <pre><code>public MyButton(Context c) { this = inflater.inflate(R.layout.mybutton, null, false); } </code></pre> <p>How can I build a custom View which has allways the same layout so I can build a new myButton with a preloaded layout like this:</p> <pre><code>MyButton myButton = new MyButton(); </code></pre> <p>This is the layout I want to use for myButton:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/cell_shape" android:orientation="vertical" android:paddingBottom="@dimen/PaddingBottom" android:paddingLeft="@dimen/PaddingHorizontal" android:paddingRight="@dimen/PaddingHorizontal" android:paddingTop="@dimen/PaddingTop" &gt; &lt;TextView android:id="@+id/Fach" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/MarginTop" android:text="" android:textAppearance="?android:attr/textAppearanceMedium" android:textStyle="bold" /&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;TextView android:id="@+id/Klasse" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="@dimen/MarginTop" android:text="" /&gt; &lt;TextView android:id="@+id/Raum" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="right" android:text="" /&gt; &lt;/LinearLayout&gt; </code></pre> <p></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.
    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