Note that there are some explanatory texts on larger screens.

plurals
  1. POLinking two XML layouts in one java file
    primarykey
    data
    text
    <p>I am creating a flashlight app...I want to link two layouts in one java file...one layout is when the torch is unlit...and the other layout shows an illuminating torch...I have worked on it and now when i press the button it shifts to the other layout..(the illuminating one)...but does not come back to the first one when i click the button...What to do? Here is the code..</p> <p>My XML1:</p> <pre><code> &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/RelativeLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@drawable/fl" tools:context=".Flash" &gt; &lt;Button android:id="@+id/ib2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:background="@drawable/bu" /&gt; </code></pre> <p></p> <p>My XML2:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/RelativeLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/fl1" android:orientation="vertical" &gt; &lt;Button android:id="@id/ib2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:background="@drawable/bu" /&gt; </code></pre> <p></p> <p>My Flashlight.java file (excluding imports):</p> <pre class="lang-java prettyprint-override"><code> package com.potapptoes.flashlight; public class Flash extends Activity implements OnClickListener { Camera cam = null; Button ib1; Parameters para; PowerManager pm; WakeLock wl; @Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "whatever"); super.onCreate(savedInstanceState); setContentView(R.layout.main); wl.acquire(); initialize(); ib1.setOnClickListener(this); } private void initialize() { // TODO Auto-generated method stub ib1 = (Button) findViewById(R.id.ib2); } @Override public void onClick(View v) { // TODO Auto-generated method stub if (cam == null) { setContentView(R.layout.main2); cam = Camera.open(); para = cam.getParameters(); para.setFlashMode(Parameters.FLASH_MODE_TORCH); cam.setParameters(para); } else { setContentView(R.layout.main); para.setFlashMode(Parameters.FLASH_MODE_OFF); cam.setParameters(para); cam.release(); cam = null; } } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); para.setFlashMode(Parameters.FLASH_MODE_OFF); cam.setParameters(para); cam.release(); cam = null; wl.release(); finish(); } } </code></pre>
    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.
 

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