공부하는 블로그

(안드로이드 프로그래밍) Activity로 화면전환제어 본문

카테고리 없음

(안드로이드 프로그래밍) Activity로 화면전환제어

모아&모지리 2017. 9. 27. 19:56
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.ktds.lesson05_1.MainActivity">
 
    <Button
        android:id="@+id/btn_1_activity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Activity1"/>
    <Button
        android:id="@+id/btn_2_activity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Activity2"/>
    <Button
        android:id="@+id/btn_3_activity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Activity3"/>
 
</LinearLayout>
 
cs

Main


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.ktds.lesson05_1.NewActivity1">
 
    <Button
        android:id="@+id/btn_close"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Close"/>
 
</LinearLayout>
 
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.ktds.lesson05_1;
 
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
 
public class MainActivity extends AppCompatActivity {
 
    private Button btn_1_activity;
    private Button btn_2_activity;
    private Button btn_3_activity;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        btn_1_activity = (Button) findViewById(R.id.btn_1_activity);
        btn_2_activity = (Button) findViewById(R.id.btn_2_activity);
        btn_3_activity = (Button) findViewById(R.id.btn_3_activity);
 
        btn_1_activity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent( MainActivity.this , NewActivity1.class);
                startActivity(intent);
            }
        });
        btn_2_activity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent( MainActivity.this , NewActivity2.class);
                startActivity(intent);
            }
        });
        btn_3_activity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent( MainActivity.this , NewActivity3.class);
                startActivity(intent);
            }
        });
    }
}
 
 
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.ktds.lesson05_1;
 
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
 
public class NewActivity1 extends AppCompatActivity {
 
    private Button btn_close;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new1);
 
        btn_close = (Button) findViewById(R.id.btn_close);
        btn_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
 
cs