Note that there are some explanatory texts on larger screens.

plurals
  1. POsetContentView() not working
    primarykey
    data
    text
    <p>Here's my code:</p> <pre> <code> public class MyActivity extends Activity implements View.OnClickListener { private Button mHorizontalButton; private Button mVerticalButton; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mHorizontalButton = (Button) findViewById(R.id.horizontal_button); mVerticalButton = (Button) findViewById(R.id.vertical_button); mHorizontalButton.setOnClickListener(this); mVerticalButton.setOnClickListener(this); } public void onClick(View v) { switch (v.getId()) { case R.id.horizontal_button: setContentView(R.layout.horizontal); break; case R.id.vertical_button: setContentView(R.layout.main); break; } } } </code> </pre> <p><strong>main.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="match_parent"&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This layout is vertical." /&gt; &lt;Button android:text="Click for a horizontal layout" android:id="@+id/horizontal_button" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>horizontal.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="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This layout is horizontal." /&gt; &lt;Button android:text="Click for a vertical layout" android:id="@+id/vertical_button" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>It is supposed, that by clicking on button I'll get the horizontal view, and then after clicking once again - vertical. </p> <p>But after clicking nothing happens. What might be the issue?</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