• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps unable to switch activity

adilshoukat

Lurker
Dec 11, 2010
4
0
Hi,
I am new to android development. I am facing problem in switching between activities. I am attaching the code files ... Please help me solve this problem

Main Activity:
Code:
package swz.pkg;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class SWMainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button btnMSrch = (Button) findViewById(R.id.btnClosetSearch);
        
        try{
        btnMSrch.setOnClickListener(new View.OnClickListener() {
        	public void onClick(View v) {
        	Intent myIntent = new Intent(v.getContext(),ClosetSearchAct.class); 
        	startActivityForResult(myIntent,0); 
        	}

        	}); 
        	}
        	catch (Exception ex)
        	{
        		System.out.println("---------------------******------------------------");
        		ex.printStackTrace();
        		System.out.println();
        		System.out.println("---------------------******------------------------");
        	} 

        
    }
}


main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>

<Button
android:id="@+id/btnMeasurementSearch"
android:layout_width="fill_parent"
android:layout_height="150px"
android:background="#ffffffff"
android:text="Measurement Search"
android:textSize="26sp"
android:typeface="serif"
android:textStyle="bold"
android:textColor="#ff8c2528"
android:layout_x="0px"
android:layout_y="47px"
>
</Button>
<Button
android:id="@+id/btnClosetSearch"
android:layout_width="fill_parent"
android:layout_height="150px"
android:text="Closet Search"
android:textSize="26sp"
android:typeface="serif"
android:textStyle="bold"
android:textColor="#ff462556"
android:layout_x="0px"
android:layout_y="213px"
>
</Button>


</AbsoluteLayout>


closetSearch activity(The next activity I want to move to):
Code:
package swz.pkg;

import android.app.Activity;
import android.os.Bundle;

public class ClosetSearchAct extends Activity {
	public void onCreate(Bundle savedInstanceState) {
	setContentView(R.layout.closetsearchact);
    
	}
}



closetsearchact.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<Spinner
android:id="@+id/spinner1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="0px"
android:layout_y="33px"
>
</Spinner>
<Spinner
android:id="@+id/spinner2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="0px"
android:layout_y="101px"
>
</Spinner>
<Spinner
android:id="@+id/spinner3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="0px"
android:layout_y="173px"
>
</Spinner>
<ImageButton
android:id="@+id/btnReg"
android:layout_width="128px"
android:layout_height="wrap_content"
android:src="@drawable/reg"
android:layout_x="151px"
android:layout_y="279px"
>
</ImageButton>
<ImageButton
android:id="@+id/btnSearch"
android:layout_width="114px"
android:layout_height="49px"
android:src="@drawable/search"
android:layout_x="37px"
android:layout_y="279px"
>
</ImageButton>
</AbsoluteLayout>



AndroidManifest.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="swz.pkg"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".SWMainActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
		<activity android:name=".ClosetSearchAct" android:label="@string/app_name"> </activity>
		
        

    </application>


</manifest>
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones