본문 바로가기

동방프로젝트

직풀 10-1

<manifest파일>

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.forseveralactivity">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".SecondActivity"
android:label="Second 액티비티" />
<activity android:name=".ThirdActivity"
android:label="Third 액티비티"/>
</application>

</manifest>

///////////////////////////////////////

<xml파일>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00ffff"
android:orientation="vertical">

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="돌아가기"
android:id="@+id/btnReturn"/>
</LinearLayout>

////////////////////

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00ff00"
android:orientation="vertical">

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="돌아가기"
android:id="@+id/btnReturn"/>

</LinearLayout>

///////////////////

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioG1">

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rdoSec"
android:checked="true"
android:text="Second 액티비티"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rdoThd"
android:text="Third 액티비티"/>
</RadioGroup>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="새 화면 열기"
android:id="@+id/btnNewActivity"/>

</LinearLayout>

/////////////////////////

<자바 파일>

package com.example.forseveralactivity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class ThirdActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.third);

Button btnReturn=(Button)findViewById(R.id.btnReturn);
btnReturn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
finish();
}
});
}
}

/////////////////

package com.example.forseveralactivity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class SecondActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);

Button btnReturn=(Button)findViewById(R.id.btnReturn);
btnReturn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
finish();
}
});
}
}

////////////////////

package com.example.forseveralactivity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("메인 액티비티(수정)");

final RadioButton rdoSecond=(RadioButton)findViewById(R.id.rdoSec);

Button btnNewActivity=(Button)findViewById(R.id.btnNewActivity);
btnNewActivity.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent;

if (rdoSecond.isChecked() == true)
intent = new Intent(getApplicationContext(),
SecondActivity.class);
else
intent = new Intent(getApplicationContext(),
ThirdActivity.class);

startActivity(intent);
}
});
}
}

'동방프로젝트' 카테고리의 다른 글

직풀 10-3  (2) 2020.08.19
실습 10-2, 직풀 10-2  (0) 2020.08.18
개선그림판 9-3  (2) 2020.08.17
그림판 만들기(9-3)  (0) 2020.08.17
실습, 직풀 9-2) 그림판 만들기  (2) 2020.08.17