일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- friend함수
- 멤버접근허용
- 함수중복
- freiend클래스
- 연산자재정의
- 랜덤출력
- jQuery
- 코딩
- 생성자호출
- 함수표현식
- this객체
- react
- 친구함수
- SQL
- 웹개발
- 제네릭 함수
- JS
- time()
- freiend선언
- 자바스크립트라이브러리
- 자바스크립트
- 프로그래밍
- new연산자
- 데이터베이스
- HTML
- 테이블
- call by referance
- C언어
- C++
- 객체지향프로그래밍
- Today
- Total
Programming Storytelling
앱 프로그래밍 본문
<?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"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="0dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Radio Button"
android:textSize="30dp" />
<Button
android:id="@+id/Btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onButtonClick"
android:text="버튼" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Radio Button"
android:textSize="30dp" />
<RadioButton
android:id="@+id/r_btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="라디오 버튼1" />
<RadioButton
android:id="@+id/r_btn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="라디오 버튼2" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Radio Group"
android:textSize="30dp" />
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rg_btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="라디오 그룹 버튼1" />
<RadioButton
android:id="@+id/rg_btn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="라디오 그룹 버튼2" />
</RadioGroup>
</LinearLayout>
</LinearLayout>
//////////////////////////////////////////////////////////
package com.example.mere;
import androidx.annotation.IdRes;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private RadioButton r_btn1, r_btn2;
private RadioGroup radioGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
r_btn1 = (RadioButton) findViewById(R.id.r_btn1);
r_btn2 = (RadioButton) findViewById(R.id.r_btn2);
r_btn1.setOnClickListener(radioButtonClickListener);
r_btn2.setOnClickListener(radioButtonClickListener);
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
radioGroup.setOnCheckedChangeListener(radioGroupButtonChangeListener);
}
public void onButtonClick(View v) {
Toast.makeText(this, "버튼을 눌렀습니다.", Toast.LENGTH_LONG).show();
}
RadioButton.OnClickListener radioButtonClickListener = new RadioButton.OnClickListener(){
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "r_btn1 : "+r_btn1.isChecked() + "r_btn2 : " +r_btn2.isChecked() , Toast.LENGTH_SHORT).show();
}
};
RadioGroup.OnCheckedChangeListener radioGroupButtonChangeListener = new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
if(i == R.id.rg_btn1){
Toast.makeText(MainActivity.this, "라디오 그룹 버튼1 눌렸습니다.", Toast.LENGTH_SHORT).show(); }
else if(i == R.id.rg_btn2){
Toast.makeText(MainActivity.this, "라디오 그룹 버튼2 눌렸습니다.", Toast.LENGTH_SHORT).show();
}
}
};
}
//////////////////////////////////////////////////////////////
<?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"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="0dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="CheckBox"
android:textSize="30dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="체크박스 선택하기"
android:textAppearance="?android:attr/textAppearanceLarge" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="체크1" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="체크2" />
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="체크3" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="선택완료" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="선택결과창"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</LinearLayout>
/////////////////////////////////////////////////////////////////////////
package com.example.mere;
import androidx.annotation.IdRes;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final CheckBox cb1 = (CheckBox) findViewById(R.id.checkBox1);
final CheckBox cb2 = (CheckBox) findViewById(R.id.checkBox2);
final CheckBox cb3 = (CheckBox) findViewById(R.id.checkBox3);
Button b = (Button)findViewById(R.id.button1);
final TextView tv = (TextView)findViewById(R.id.textView2);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String result = ""; // 결과를 출력할 문자열 , 항상 스트링은 빈문자열로 초기화 하는 습관을 가지자
if(cb1.isChecked() == true) result += cb1.getText().toString();
if(cb2.isChecked() == true) result += cb2.getText().toString();
if(cb3.isChecked() == true) result += cb3.getText().toString();
tv.setText("선택결과:" + result);
}
});
}
}
//////////////////////////////////////////////////////////////////////
<?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"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="0dp">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText1"
android:text="TEXT1" />
</LinearLayout>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////package com.example.mere;
import androidx.annotation.IdRes;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText editText1 = (EditText) findViewById(R.id.editText1) ;
editText1.setText("The text of EditText is changed.") ;
}
}