Skip to content

Commit 621eb02

Browse files
committed
More activities
1 parent b506d9f commit 621eb02

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

AndroidManifest.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,17 @@
2727
android:label="CheckBox Activity" >
2828
</activity>
2929
<activity
30-
android:name=".CatActivity"
30+
android:name="com.example.helloworld.CatActivity"
3131
android:label="Cat Activity" >
3232
</activity>
33+
<activity
34+
android:name="com.example.helloworld.PreferenceActivity"
35+
android:label="Preference Activity" >
36+
</activity>
37+
<activity
38+
android:name="com.example.helloworld.TextFileActivity"
39+
android:label="TextFile Activity" >
40+
</activity>
3341
</application>
3442

3543
</manifest>

res/layout/activity_main.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
android:id="@+id/button1"
1313
android:layout_width="wrap_content"
1414
android:layout_height="wrap_content"
15-
android:text="Button" />
15+
android:text="Cat" />
1616

1717
<Button
1818
android:id="@+id/button2"
1919
android:layout_width="wrap_content"
2020
android:layout_height="wrap_content"
21-
android:text="Button" />
21+
android:text="Pref" />
2222

2323
<Button
2424
android:id="@+id/button3"
2525
android:layout_width="wrap_content"
2626
android:layout_height="wrap_content"
27-
android:text="Button" />
27+
android:text="Text" />
2828

2929
<Button
3030
android:id="@+id/button4"

src/com/example/helloworld/MainActivity.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,30 @@
22

33
import android.os.Bundle;
44
import android.app.Activity;
5+
import android.content.Context;
6+
import android.content.Intent;
57
import android.view.Menu;
68
import android.view.View;
79
import android.widget.Button;
810

911
public class MainActivity extends Activity {
1012

11-
private Button catButton;
12-
13+
private Button button1;
14+
private Button button2;
15+
private Button button3;
16+
private Context context;
17+
1318
@Override
1419
protected void onCreate(Bundle savedInstanceState) {
1520
super.onCreate(savedInstanceState);
1621
setContentView(R.layout.activity_main);
17-
catButton = (Button) findViewById(R.id.catButton);
18-
catButton.setOnClickListener(new MyOnClickListener());
22+
context = this;
23+
button1 = (Button) findViewById(R.id.button1);
24+
button1.setOnClickListener(new MyOnClickListener());
25+
button2 = (Button) findViewById(R.id.button2);
26+
button2.setOnClickListener(new MyOnClickListener());
27+
button3 = (Button) findViewById(R.id.button3);
28+
button3.setOnClickListener(new MyOnClickListener());
1929
}
2030

2131
@Override
@@ -24,11 +34,18 @@ public boolean onCreateOptionsMenu(Menu menu) {
2434
getMenuInflater().inflate(R.menu.activity_main, menu);
2535
return true;
2636
}
27-
37+
2838
public class MyOnClickListener implements View.OnClickListener {
2939
@Override
3040
public void onClick(View arg0) {
31-
41+
if (arg0.getId() == R.id.button1) {
42+
Intent intent = new Intent(context, CatActivity.class);
43+
startActivity(intent);
44+
} else if (arg0.getId() == R.id.button2) {
45+
startActivity(new Intent(context, PreferenceActivity.class));
46+
} else if (arg0.getId() == R.id.button3) {
47+
startActivity(new Intent(context, TextFileActivity.class));
48+
}
3249
}
3350
}
3451

0 commit comments

Comments
 (0)