Note that there are some explanatory texts on larger screens.

plurals
  1. POUse declare styleable to set custom component input type
    primarykey
    data
    text
    <p>I have a CompositeComponent (EditText+ImageButton) When clicking on button the edittext content will be cleared. It is working fine. My problem is setting attributes to my component. I am using declare-styleable to set attributes to my component. </p> <p>I am successful at setting minLines, maxLines and textColor.</p> <p>How can I set inputtype to my component via xml.</p> <p>my attributes.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;declare-styleable name="CET"&gt; &lt;attr name="MaxLines" format="integer"/&gt; &lt;attr name="MinLines" format="integer"/&gt; &lt;attr name="TextColor" format="color"/&gt; &lt;attr name="InputType" format="integer" /&gt; &lt;attr name="Hint" format="string" /&gt; &lt;/declare-styleable&gt; &lt;/resources&gt; </code></pre> <p>And usage of mycomponent in main_layout.xml:</p> <pre><code>&lt;com.test.ui.ClearableEditText xmlns:cet="http://schemas.android.com/apk/res/com.test.ui" android:id="@+id/clearableEditText2" android:layout_width="wrap_content" android:layout_height="wrap_content" cet:MaxLines="2" cet:MinLines="1" cet:TextColor="#0000FF" cet:InputType="" &lt;---I cant set this property---------&gt; cet:Hint="Clearable EditText Hint"&gt; &lt;/com.test.ui.ClearableEditText&gt; </code></pre> <p>Ordinary Edittext usage:</p> <pre><code>&lt;EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="numberSigned" &lt;--------I want to use this property--------&gt; &gt; </code></pre> <p>I cant use ENUM in my attribute.xml. How to refer <code>android:inputType="numberSigned"</code> in my <code>cet:InputType</code>?</p> <p><strong>EDIT:</strong></p> <p>This is how I assign properties in my ClearableEditText.java</p> <pre><code>TypedArray a = getContext().obtainStyledAttributes(attrs,R.styleable.CET,0, 0); int minLines = a.getInt(R.styleable.CET_MinLines, 1); int maxLines = a.getInt(R.styleable.CET_MaxLines, 100); String hint = a.getString(R.styleable.CET_Hint); int textColor = a.getColor(R.styleable.CET_TextColor, Color.BLACK); int inputType = a.getInt(R.styleable.CET_InputType, -108); Log.i(TAG, "ClearableEditText: Min Line "+minLines +" Max Lines: "+maxLines+" Hint "+hint+" Color: "+textColor+" Input Type: "+inputType); edit_text.setMaxLines(maxLines); edit_text.setMinLines(minLines); edit_text.setTextColor(textColor); edit_text.setHint(hint); if(inputType != -108) edit_text.setInputType(inputType); </code></pre> <p>You can see there is no problem with assigning the inputType property to editText.</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.
 

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