/* Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
This code is for educational purposes only. Use at own risk.*/

1. package com.javalessons.simplexml2; 

2.  

3. import android.os.Bundle

4. import android.app.Activity

5. import android.content.Intent

6. import android.view.View

7. import android.view.View.OnClickListener

8. import android.widget.Button

9.  

10. public class MainActivity extends Activity

11.  

12.   Button bt; 

13.    

14.   @Override 

15.   protected void onCreate(Bundle savedInstanceState) { 

16.     super.onCreate(savedInstanceState); 

17.     setContentView(R.layout.activity_main); 

18.  

19.     bt = (Button) findViewById(R.id.button1); 

20.      

21.     bt.setOnClickListener( new OnClickListener() { 

22.  

23.       @Override 

24.       public void onClick(View v) { 

25.           Intent intent = new Intent(MainActivity.this, Activity2.class); 

26.                 startActivity(intent);  

27.       } 

28.     }); 

29.   } 

30.

31. //=====================================   

32. // Activity2.java : 

33. package com.javalessons.simplexml2; 

34.  

35. import android.os.Bundle

36. import android.app.Activity

37.  

38. public class Activity2 extends Activity

39.  

40.   @Override 

41.   protected void onCreate(Bundle savedInstanceState) { 

42.     super.onCreate(savedInstanceState); 

43.     setContentView(R.layout.activity_activity2); 

44.   } 

45.

46. //end of Java file 

47.  

48. ====== res/layout/activity_main.xml : =========== 

49. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 

50.     xmlns:tools="http://schemas.android.com/tools" 

51.     android:id="@+id/LinearLayout1" 

52.     android:layout_width="match_parent" 

53.     android:layout_height="match_parent" 

54.     android:background="#ff00ffff" 

55.     android:orientation="vertical" 

56.     android:paddingBottom="@dimen/activity_vertical_margin" 

57.     android:paddingLeft="@dimen/activity_horizontal_margin" 

58.     android:paddingRight="@dimen/activity_horizontal_margin" 

59.     android:paddingTop="@dimen/activity_vertical_margin" 

60.     tools:context=".MainActivity"

61.  

62.     <TextView 

63.         android:id="@+id/textView1" 

64.         android:layout_width="wrap_content" 

65.         android:layout_height="wrap_content" 

66.         android:text="Screen 1" 

67.         android:textAppearance="?android:attr/textAppearanceLarge" /> 

68.  

69.     <Button 

70.         android:id="@+id/button1" 

71.         android:layout_width="wrap_content" 

72.         android:layout_height="wrap_content" 

73.         android:text="Button" /> 

74.  

75. </LinearLayout

76.  

77. ====== res/layout/activity_activity2.xml : =========== 

78. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 

79.     xmlns:tools="http://schemas.android.com/tools" 

80.     android:id="@+id/LinearLayout1" 

81.     android:layout_width="match_parent" 

82.     android:layout_height="match_parent" 

83.     android:background="#ff00ff00" 

84.     android:orientation="vertical" 

85.     android:paddingBottom="@dimen/activity_vertical_margin" 

86.     android:paddingLeft="@dimen/activity_horizontal_margin" 

87.     android:paddingRight="@dimen/activity_horizontal_margin" 

88.     android:paddingTop="@dimen/activity_vertical_margin" 

89.     tools:context=".Activity2"

90.  

91.     <TextView 

92.         android:id="@+id/textView1" 

93.         android:layout_width="wrap_content" 

94.         android:layout_height="wrap_content" 

95.         android:text="@string/tvtext" 

96.         android:textAppearance="?android:attr/textAppearanceLarge" /> 

97.  

98. </LinearLayout

99.  

100. ======= res/values/strings.xml : ======== 

101. <?xml version="1.0" encoding="utf-8"?> 

102. <resources> 

103.  

104.     <string name="app_name">SimpleXML2</string> 

105.     <string name="action_settings">Settings</string> 

106.     <string name="title_activity_activity2">Activity2</string> 

107.     <string name="tvtext">Screen 2</string> 

108.      

109. </resources>