Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use Compound Controls
    primarykey
    data
    text
    <p>I've created a custom ViewGroup based on a LinearLayout.</p> <p><strong>ClearableEditText.java</strong></p> <pre><code>package test.todolist; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; public class ClearableEditText extends LinearLayout{ private EditText editText; private Button button; public ClearableEditText (Context context){ super (context); String service = Context.LAYOUT_INFLATER_SERVICE; LayoutInflater li = (LayoutInflater)getContext ().getSystemService (service); li.inflate (R.layout.clearable_edit_text, this, true); editText = (EditText)findViewById (R.id.clearEditText); button = (Button)findViewById (R.id.clearButton); configButton (); } private void configButton (){ button.setOnClickListener (new Button.OnClickListener (){ public void onClick (View v){ editText.setText (""); } }); } } </code></pre> <p><strong>clearable_edit_text.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"&gt; &lt;EditText android:id="@+id/clearEditText" android:layout_width="match_parent" android:layout_height="wrap_content" /&gt; &lt;Button android:id="@+id/clearButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/clear" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>How can I use ClearableEditText now?</p> <p>I've tried to put a node inside a layout (main.xml) in 2 ways:</p> <pre><code>&lt;test.todolist.ClearableEditText/&gt; </code></pre> <p>and </p> <pre><code>&lt;test.todolist.clearable_edit_text/&gt; </code></pre> <p>but none of them have worked.</p> <p>My <strong>main.xml</strong>:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;test.todolist.ClearableEditText/&gt; </code></pre> <p>My <strong>ToDoList.java</strong> (main activity):</p> <pre><code>package test.todolist; import android.app.Activity; import android.os.Bundle; public class ToDoList extends Activity{ @Override public void onCreate (Bundle savedInstanceState){ super.onCreate (savedInstanceState); setContentView (R.layout.main); } } </code></pre> <p>Thanks.</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