Note that there are some explanatory texts on larger screens.

plurals
  1. POsetContentView and EditText
    primarykey
    data
    text
    <p>I have two layouts xml and can't get the second layout to work correctly. A EditText placed on the second layout doesn't work as expected. It doesn't accept characters.</p> <p>What am i missing here? Should i use startActivity() instead?</p> <p>Main.java</p> <pre><code>public class Main extends Activity implements View.OnClickListener { EditText box1, box2; @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); showXml1(); } public void onClick(View v) { switch (v.getId()) { case R.id.button1: String box11 = box1.getText().toString(); Toast.makeText(this, box11,Toast.LENGTH_SHORT).show(); showXml2(); break; case R.id.button2: String box22 = box2.getText().toString(); Toast.makeText(this, box22,Toast.LENGTH_SHORT).show(); showXml1(); break; } } public void showXml2() { setContentView(R.layout.main2); box2 = (EditText) findViewById(R.id.editText2); } public void showXml1() { setContentView(R.layout.main); box1 = (EditText) findViewById(R.id.editText1); } } </code></pre> <p>main.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Main1" /&gt; &lt;EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;requestFocus /&gt; &lt;/EditText&gt; &lt;Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button1" android:onClick="onClick" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>mail2.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Main2" /&gt; &lt;EditText android:id="@+id/editText2" android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;requestFocus /&gt; &lt;/EditText&gt; &lt;Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button2" android:onClick="onClick" /&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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