모바일/android

[안드로이드프로그래밍 6판] 2장 직접 풀어보기 2-3, 연습 문제 7

2021. 10. 15. 17:53
728x90
반응형
직접 풀어보기 2-3

정답지 아닙니다.

블로그 주인이 생각한 코드라서

오타, 오류 있을 수 있습니다.

(>> 댓글로 알려주시면 정정하겠습니다!)

 

 

<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:orientation="vertical">

    <Button
        android:id="@+id/site"
        android:text="네이트 홈페이지 열기"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#A6A6A6"/>
    <Button
        android:id="@+id/call"
        android:text="911 응급전화 걸기"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#008F00"/>
    <Button
        android:id="@+id/gallery"
        android:text="갤러리 열기"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FF0000"/>
    <Button
        android:id="@+id/end"
        android:text="끝내기"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFE500"/>

</LinearLayout>

<java 코드>

package com.cookandroid.myself2_3;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.ActionMode;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button Site, Call, Gallery, End;

        Site = findViewById(R.id.site);
        Call = findViewById(R.id.call);
        Gallery = findViewById(R.id.gallery);
        End = findViewById(R.id.end);

        Site.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://m.nate.com"));
                startActivity(mIntent);
            }
        });

        Call.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:/911"));
                startActivity(mIntent);
            }
        });

        Gallery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/internal/images/media"));
                startActivity(mIntent);
            }
        });
        End.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
}

 

 

연습 문제 7

<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:orientation="vertical">

    <EditText
        android:id="@+id/Site"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <Button
        android:id="@+id/BtnShow"
        android:text="글자 나타내기"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <Button
        android:id="@+id/BtnOpen"
        android:text="홈페이지 열기"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <RadioButton
            android:id="@+id/Q"
            android:text="Q(10)"
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <RadioButton
            android:id="@+id/R"
            android:text="R(11)"
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </RadioGroup>

    <ImageView
        android:id="@+id/View"
        android:layout_gravity="center"
        android:layout_width="300dp"
        android:layout_height="300dp"/>
</LinearLayout>

<java 코드>

package com.cookandroid.pr2_7;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setTitle("좀 그럴듯한 앱");

        EditText site;
        Button btnShow, btnOpen;
        RadioButton q, r;
        ImageView view;

        site = findViewById(R.id.Site);
        btnShow = findViewById(R.id.BtnShow);
        btnOpen = findViewById(R.id.BtnOpen);
        q = findViewById(R.id.Q);
        r = findViewById(R.id.R);
        view = findViewById(R.id.View);

        btnShow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getApplicationContext(), site.getText(), Toast.LENGTH_SHORT).show();
            }
        });
        btnOpen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent a = new Intent(Intent.ACTION_VIEW, Uri.parse(String.valueOf(site.getText())));
                startActivity(a);
            }
        });

        q.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b==true) {
                    view.setImageResource(R.drawable.q10);
                }
            }
        });

        r.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b==true) {
                    view.setImageResource(R.drawable.r11);
                }
            }
        });
    }
}
저작자표시 비영리 (새창열림)

'모바일 > android' 카테고리의 다른 글

[안드로이드프로그래밍6판] 4장 실습 4-2, 직접 풀어보기 4-4  (0) 2021.10.16
[안드로이드프로그래밍6판] 4장 직접 풀어보기 4-2, 4-3 실습 4-1  (0) 2021.10.15
[android_기초] 새로운 위젯 형성의 흐름, Toast 메시지 이용  (0) 2021.09.13
[android_기초] 참고: xml 문서 작성방법  (0) 2021.09.13
[Android_기초] 인텐트(intent) 화면 간 이동, 데이터 전달  (0) 2021.08.18
'모바일/android' 카테고리의 다른 글
  • [안드로이드프로그래밍6판] 4장 실습 4-2, 직접 풀어보기 4-4
  • [안드로이드프로그래밍6판] 4장 직접 풀어보기 4-2, 4-3 실습 4-1
  • [android_기초] 새로운 위젯 형성의 흐름, Toast 메시지 이용
  • [android_기초] 참고: xml 문서 작성방법
hatch
hatch
250x250
hatch
차근차근 쌓아올리는,
hatch
전체
오늘
어제
  • 분류 전체보기 (121)
    • TIL (3)
    • [JAVA] (17)
      • 생활코딩 (11)
    • 모바일 (25)
      • android (24)
      • ReactNative (1)
    • 웹개발 (25)
      • React (3)
      • jQuery (5)
      • Springboot (2)
    • 알고리즘 (42)
    • [프로그래밍기초지식] (1)
    • [기술문서 읽기] (0)
      • 개념 번역 (0)
    • 인사이트(insight) (2)
    • git (2)

블로그 메뉴

  • 홈
  • 태그
  • 방명록
  • write
  • manger

공지사항

인기 글

태그

  • jquery
  • 타일링
  • 반복문
  • 별찍기
  • BufferedReader
  • 안드로이드프로그래밍6판
  • DP
  • TIL
  • 중복리니어레이아웃
  • 모프2주차
  • 명시적 인텐트
  • scanf
  • 재귀
  • 210908
  • 깊은복사
  • javascript
  • 백준
  • 노이클립스
  • state
  • Doit!자바프로그래밍입문

최근 댓글

최근 글

hELLO · Designed By 정상우.
hatch
[안드로이드프로그래밍 6판] 2장 직접 풀어보기 2-3, 연습 문제 7
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.