본문 바로가기
안드로이드 프로그래밍

안드로이드 개발 - 버튼으로 화면 전환하기

by 자유코딩 2018. 8. 20.

클래스 구조

 

 

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.ex1.jswoo.myapplication;
 
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.LinearLayout;
 
public class MainActivity extends AppCompatActivity {
    LinearLayout linearLayout;
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    public void monClicked(View v){
        linearLayout = (LinearLayout)findViewById(R.id.task);
        linearLayout.removeAllViews();
        LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.activity_monday,linearLayout,true);
    }
    public void tuesClicked(View v){
        linearLayout = (LinearLayout)findViewById(R.id.task);
        linearLayout.removeAllViews();
        LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.activity_tuesday,linearLayout,true);
    }
    public void wednesClicked(View v){
        linearLayout = (LinearLayout)findViewById(R.id.task);
        linearLayout.removeAllViews();
        LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.activity_wednesday,linearLayout,true);
 
    }
    public void thursClicked(View v){
        linearLayout = (LinearLayout)findViewById(R.id.task);
        linearLayout.removeAllViews();
        LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.activity_thursday,linearLayout,true);
 
    }
    public void friClicked(View v){
        linearLayout = (LinearLayout)findViewById(R.id.task);
        linearLayout.removeAllViews();
        LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.activity_friday,linearLayout,true);
 
    }
    public void saturClicked(View v){
        linearLayout = (LinearLayout)findViewById(R.id.task);
        linearLayout.removeAllViews();
        LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.activity_saturday,linearLayout,true);
    }
    public void sunClicked(View v){
        linearLayout = (LinearLayout)findViewById(R.id.task);
        linearLayout.removeAllViews();
        LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.activity_sunday,linearLayout,true);
    }
}
 
cs

 

만든 xml 파일들

 

 

화면 상태

 

 

 

일요일까지 전환 가능

 

댓글