일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Writeup
- 덧셈 암호
- 호이스팅
- function scope
- 한국정보보호산업협회
- 포너블
- 한국정보보호산업협회기자단
- 백엔드
- 개인정보보호위원회
- 모듈러 연산
- 개인정보보호교육
- 유클리드_알고리즘
- arrow function
- 백엔드입문
- 마감임박
- 디오판투스 알고리즘
- package.json
- 개인정보안전성
- 동적타이핑
- 한국산업인력공단
- 웹 프레임워크
- package-lock.json
- 가명정보처리
- 개인정보보호
- 무료교육
- 확장 유클리드 알고리즘
- 곱셈 암호
- 국가인적자원개발컨소시엄
- pwnable.tw
- node.js
- Today
- Total
짱짱해커가 되고 싶은 나
02-3. BaseApp2 구현 본문
* BaseApp2 기능
EditText - 글자 입력
버튼1 - 입력한 글자 잠깐 나타내기
버튼2 - 입력한 주소의 홈페이지 열기
ImageView - 처음에는 기본 이미지
RadioGroup1개 - RadioButton2 - 오레오, 파이 선택 버튼 -> 선택된 버튼의 이미지로 바뀜(ImageView)
<activity_main.xml>
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/edit_text"
android:hint="주소를 입력하세요"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textUri">
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/strBtn1">
</Button>
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/strBtn2">
</Button>
<RadioGroup
android:id="@+id/r_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/r_button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/strRbtn1" />
<RadioButton
android:id="@+id/r_button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/strRbtn2" />
</RadioGroup>
<ImageView
android:id="@+id/i_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/android_default_icon"/>
</LinearLayout>
EditText : TextView로부터 파생된 클래스로 TextView는 단순히 텍스트를 보여주는 역할만 하는 반면, EditText는 Text를 입력/수정까지 가능한 뷰 위젯이다. 에딧텍스트를 누르면 기존에 있던 문자열은 삭제되고 새로 입력된다.
- hint : EditText 배경에 속성값으로 지정한 문자열을 나타나게 하는 속성
- getText() : EditText에서 Text 가져오는 함수
RadioButton : 여러 종류의 선택 항목에서 한 가지를 선택하는 형태의 버튼이다.
RadioButton은 RadioGroup내에 존재하는데 그룹 내의 라디오 버튼이 존재해야 버튼 리스트 중 하나를 누를 수 있다.
(== 한 그룹 내 1개 이기 때문에 버튼이 그룹 내에 없다면 다 선택이 가능하다)
ImageView : TextView와 마찬가지로 View 클래스로부터 상속된 이미지를 보여주는 클래스다.
Drawable 폴더에 화면에 표시할 이미지 리소스를 추가하고 이 리소스 id를 ImageView의 src 속성에 지정하면된다.
이미지 리소스의 파일이름으로 id를 만들기 때문에 파일이름에 한글이나 특수문자가 포함되어서는 안된다.
- setImageResource(): ImageView에서 출력하는 이미지 변경
<MainActivity.java>
package com.example.baseapp2;
import androidx.annotation.IdRes;
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.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText editText;
Button button1, button2;
RadioGroup radioGroup;
RadioButton rButton1, rButton2;
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText)findViewById(R.id.edit_text);
button1 = (Button)findViewById(R.id.button1);
button2 = (Button)findViewById(R.id.button2);
radioGroup = (RadioGroup)findViewById(R.id.r_group);
rButton1 = (RadioButton)findViewById(R.id.r_button1);
rButton2 = (RadioButton)findViewById(R.id.r_button2);
imageView = (ImageView)findViewById(R.id.i_view);
button1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
String getText = editText.getText().toString();
Toast.makeText(getApplicationContext(), getText , Toast.LENGTH_SHORT).show();
}
});
button2.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
String getText = editText.getText().toString();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getText));
startActivity(intent);
}
});
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(checkedId == R.id.r_button1){
imageView.setImageResource(R.drawable.android_oreo_icon);
}
else if(checkedId == R.id.r_button2){
imageView.setImageResource(R.drawable.android_pie_icon);
}
}
});
}
}
헤헤 잘 돌아간당 귀여웡~~
'모바일' 카테고리의 다른 글
04-1. View (0) | 2021.02.15 |
---|---|
03. Java 정리 (0) | 2021.02.15 |
02-2. Android 프로젝트 구성 (0) | 2021.01.28 |
02-1. 여러 기능을 하는 버튼 애플리케이션 구현 (0) | 2021.01.23 |
02. 안드로이드 프로젝트 기본 틀 (0) | 2021.01.22 |