Linking two XML layouts in one java file

abayhomes

New Member
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..My XML1:\[code\] <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" ><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" />\[/code\]My XML2:\[code\] <?xml version="1.0" encoding="utf-8"?> <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" ><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" />\[/code\]My Flashlight.java file (excluding imports):\[code\] package com.potapptoes.flashlight; public class Flash extends Activity implements OnClickListener {Camera cam = null;Button ib1;Parameters para;PowerManager pm;WakeLock wl;@Overrideprotected 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);}@Overridepublic 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; }}@Overrideprotected 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\]
 
Back
Top