1. Check out our companion app, Forums for Android! Download from Google Play

unable to switch activity

Discussion in 'Application Development' started by adilshoukat, Dec 11, 2010.

  1. adilshoukat

    adilshoukat New Member
    Thread Starter
    5

    Dec 11, 2010
    4
    0
    5
    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 (Text):
    1.  
    2. package swz.pkg;
    3.  
    4. import android.app.Activity;
    5. import android.content.Intent;
    6. import android.os.Bundle;
    7. import android.view.View;
    8. import android.widget.Button;
    9.  
    10. public class SWMainActivity extends Activity {
    11.     /** Called when the activity is first created. */
    12.     @Override
    13.     public void onCreate(Bundle savedInstanceState) {
    14.         super.onCreate(savedInstanceState);
    15.         setContentView(R.layout.main);
    16.        
    17.         Button btnMSrch = (Button) findViewById(R.id.btnClosetSearch);
    18.        
    19.         try{
    20.         btnMSrch.setOnClickListener(new View.OnClickListener() {
    21.             public void onClick(View v) {
    22.             Intent myIntent = new Intent(v.getContext(),ClosetSearchAct.class);
    23.             startActivityForResult(myIntent,0);
    24.             }
    25.  
    26.             });
    27.             }
    28.             catch (Exception ex)
    29.             {
    30.                 System.out.println("---------------------******------------------------");
    31.                 ex.printStackTrace();
    32.                 System.out.println();
    33.                 System.out.println("---------------------******------------------------");
    34.             }
    35.  
    36.        
    37.     }
    38. }
    39.  

    main.xml
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <AbsoluteLayout
    4. android:id="@+id/widget0"
    5. android:layout_width="fill_parent"
    6. android:layout_height="fill_parent"
    7. xmlns:android="http://schemas.android.com/apk/res/android"
    8. >
    9.  
    10. <Button
    11. android:id="@+id/btnMeasurementSearch"
    12. android:layout_width="fill_parent"
    13. android:layout_height="150px"
    14. android:background="#ffffffff"
    15. android:text="Measurement Search"
    16. android:textSize="26sp"
    17. android:typeface="serif"
    18. android:textStyle="bold"
    19. android:textColor="#ff8c2528"
    20. android:layout_x="0px"
    21. android:layout_y="47px"
    22. >
    23. </Button>
    24. <Button
    25. android:id="@+id/btnClosetSearch"
    26. android:layout_width="fill_parent"
    27. android:layout_height="150px"
    28. android:text="Closet Search"
    29. android:textSize="26sp"
    30. android:typeface="serif"
    31. android:textStyle="bold"
    32. android:textColor="#ff462556"
    33. android:layout_x="0px"
    34. android:layout_y="213px"
    35. >
    36. </Button>
    37.  
    38.  
    39. </AbsoluteLayout>
    40.  

    closetSearch activity(The next activity I want to move to):
    Code (Text):
    1.  
    2. package swz.pkg;
    3.  
    4. import android.app.Activity;
    5. import android.os.Bundle;
    6.  
    7. public class ClosetSearchAct extends Activity {
    8.     public void onCreate(Bundle savedInstanceState) {
    9.     setContentView(R.layout.closetsearchact);
    10.    
    11.     }
    12. }
    13.  
    14.  


    closetsearchact.xml
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <AbsoluteLayout
    4. android:id="@+id/widget1"
    5. android:layout_width="fill_parent"
    6. android:layout_height="fill_parent"
    7. xmlns:android="http://schemas.android.com/apk/res/android"
    8. >
    9. <Spinner
    10. android:id="@+id/spinner1"
    11. android:layout_width="fill_parent"
    12. android:layout_height="wrap_content"
    13. android:layout_x="0px"
    14. android:layout_y="33px"
    15. >
    16. </Spinner>
    17. <Spinner
    18. android:id="@+id/spinner2"
    19. android:layout_width="fill_parent"
    20. android:layout_height="wrap_content"
    21. android:layout_x="0px"
    22. android:layout_y="101px"
    23. >
    24. </Spinner>
    25. <Spinner
    26. android:id="@+id/spinner3"
    27. android:layout_width="fill_parent"
    28. android:layout_height="wrap_content"
    29. android:layout_x="0px"
    30. android:layout_y="173px"
    31. >
    32. </Spinner>
    33. <ImageButton
    34. android:id="@+id/btnReg"
    35. android:layout_width="128px"
    36. android:layout_height="wrap_content"
    37. android:src="@drawable/reg"
    38. android:layout_x="151px"
    39. android:layout_y="279px"
    40. >
    41. </ImageButton>
    42. <ImageButton
    43. android:id="@+id/btnSearch"
    44. android:layout_width="114px"
    45. android:layout_height="49px"
    46. android:src="@drawable/search"
    47. android:layout_x="37px"
    48. android:layout_y="279px"
    49. >
    50. </ImageButton>
    51. </AbsoluteLayout>
    52.  
    53.  


    AndroidManifest.xml:
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    4.       package="swz.pkg"
    5.       android:versionCode="1"
    6.       android:versionName="1.0">
    7.     <application android:icon="@drawable/icon" android:label="@string/app_name">
    8.         <activity android:name=".SWMainActivity"
    9.                   android:label="@string/app_name">
    10.             <intent-filter>
    11.                 <action android:name="android.intent.action.MAIN" />
    12.                 <category android:name="android.intent.category.LAUNCHER" />
    13.             </intent-filter>
    14.         </activity>
    15.        
    16.         <activity android:name=".ClosetSearchAct" android:label="@string/app_name"> </activity>
    17.        
    18.        
    19.  
    20.     </application>
    21.  
    22.  
    23. </manifest>
    24.  
     

    Advertisement

Share This Page

Loading...