My simple apps crashes immediately when I tried to add two button onclick events. Can you tell my what am I doing wrong here? thanks
EDIT... When I put one(any) of the button setOnClickListener in a comment, thus disabling action for the button , the apps loads normally. I could click on the button and it shows the other view, but I can't go back since no action is set from the other button.
file: demo1.java
Using java Syntax Highlighting
- package mrm.demo1;
- import android.app.Activity;
- import android.os.Bundle;
- import android.widget.Button;
- import android.view.View;
- import android.view.Window;
- import android.view.WindowManager;
- import android.view.View.OnClickListener;
- public class demo1 extends Activity {
- /** Called when the activity is first created. */
- public int counter;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- this.setFullscreen();
- this.setNoTitle();
- setContentView(R.layout.main);
- Button btnDemo = (Button)findViewById(R.id.btnDemo);
- btnDemo.setOnClickListener( new OnClickListener(){
- @Override
- public void onClick(View v)
- {
- setContentView(R.layout.demo1);
- }
- });
- Button btnMain = (Button)findViewById(R.id.btnMain);
- btnMain.setOnClickListener( new OnClickListener(){
- @Override
- public void onClick(View v)
- {
- setContentView(R.layout.main);
- }
- });
- }
- ////////////////////////////////
- public void setFullscreen() {
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- }
- ////////////////////////////////////
- public void setNoTitle() {
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- }
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
file: demo1.xml
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="UTF-8"?>
- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="This is the 'demo1.xml' view."
- android:layout_gravity="center_horizontal"
- />
- <Button
- android:id="@+id/btnMain"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Open MainView"
- android:hint="Click to open main view"
- android:textSize="10px"
- android:layout_gravity="center_horizontal|bottom"
- />
- <ImageView
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:scaleType="center"
- android:src="@drawable/property"
- />
- </FrameLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4
file: main.xml
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="This is the 'main.xml' view."
- android:layout_gravity="center_horizontal"
- />
- <Button
- android:id="@+id/btnDemo"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Open DemoView"
- android:hint="Click to open demo view"
- android:textSize="10px"
- android:layout_gravity="center_horizontal|bottom"
- />
- <ImageView
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:scaleType="center"
- android:src="@drawable/insurance"
- />
- </FrameLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4
file: AndroidManifest.xml
Using xml Syntax Highlighting
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="mrm.demo1"
- android:versionCode="1"
- android:versionName="1.0.0">
- <application android:label="@string/app_name" android:icon="@drawable/property">
- <activity android:name=".demo1"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


