안드로이드

 

class MainActivity
package com.example.choi.mystudy12;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

public class MainActivity extends AppCompatActivity {

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

    public void onClick(View v){
        Intent intent=null;
        switch (v.getId()){
            case R.id.button1:
                intent=new Intent(this, CheckBoxActivity.class);
                break;
            case R.id.button2:
                intent=new Intent(this, RadioButtonAtivity.class);
                break;
            case R.id.button3:
                intent=new Intent(this, ProgressBarActivity.class);
                break;
            case R.id.button4:
                intent=new Intent(this, SeekBarActivity.class);
                break;
        }
        startActivity(intent);
    }



}

 

R.layout.activity_main
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.choi.mystudy12.MainActivity">

    <Button
        android:text="CheckBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:id="@+id/button1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:onClick="onClick"
        />

    <Button
        android:text="Radio Button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="29dp"
        android:id="@+id/button2"
        android:onClick="onClick"
        />

    <Button
        android:text="ProgressBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button3"
        android:onClick="onClick"
        android:layout_below="@+id/button2"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="31dp" />

    <Button
        android:text="SeekBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button4"
        android:layout_below="@+id/button3"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="22dp"
        android:onClick="onClick"
        />


</RelativeLayout>

 

 

 

 

 

 

 

class CheckBoxActivity
package com.example.choi.mystudy12;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;

public class CheckBoxActivity extends AppCompatActivity {

    CheckBox cb1, cb2, cb3, cb4;

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

        cb1=(CheckBox)findViewById(R.id.ch_01);
        cb2=(CheckBox)findViewById(R.id.ch_02);
        cb3=(CheckBox)findViewById(R.id.ch_03);
        cb4=(CheckBox)findViewById(R.id.ch_04);

        cb1.setOnCheckedChangeListener(checkedChangeListener);
        cb2.setOnCheckedChangeListener(checkedChangeListener);
        cb3.setOnCheckedChangeListener(checkedChangeListener);
        cb4.setOnCheckedChangeListener(checkedChangeListener);

    }


    CompoundButton.OnCheckedChangeListener checkedChangeListener
            =new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            switch (buttonView.getId()){

                case R.id.ch_01:
                    Toast.makeText(CheckBoxActivity.this,
                            buttonView.getText()+", "+isChecked,
                            Toast.LENGTH_SHORT
                            ).show();
                    break;

                case R.id.ch_02:
                    Toast.makeText(CheckBoxActivity.this,
                            buttonView.getText()+", "+isChecked,
                            Toast.LENGTH_SHORT
                    ).show();
                    break;

                case R.id.ch_03:
                    Toast.makeText(CheckBoxActivity.this,
                            buttonView.getText()+", "+isChecked,
                            Toast.LENGTH_SHORT
                    ).show();
                    break;

                case R.id.ch_04:
                    Toast.makeText(CheckBoxActivity.this,
                            buttonView.getText()+", "+isChecked,
                            Toast.LENGTH_SHORT
                    ).show();
                    break;

            }

        }
    };








}

 

R.layout.activity_check_box
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_check_box"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.choi.mystudy12.CheckBoxActivity">

    <TextView
        android:text="당신의 취미는?"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:id="@+id/textView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textSize="18sp"
        android:textStyle="normal|bold" />

    <CheckBox
        android:text="요리"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ch_01"
        android:id="@+id/ch_02"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="10dp" />

    <CheckBox
        android:text="독서"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ch_02"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/ch_03"
        android:layout_marginBottom="10dp" />

    <CheckBox
        android:text="여행"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ch_03"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/ch_04" />

    <CheckBox
        android:text="운동"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/ch_01"
        android:layout_below="@+id/textView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp" />
</RelativeLayout>

 

 

 

 

 

 

 

class RadioButtonAtivity 
package com.example.choi.mystudy12;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.RadioGroup;
import android.widget.Toast;

public class RadioButtonAtivity extends AppCompatActivity {


    RadioGroup rg=null;

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

        rg=(RadioGroup)findViewById(R.id.rg_01);

        rg.setOnCheckedChangeListener(changeListener);

    }


    RadioGroup.OnCheckedChangeListener changeListener =new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            switch (checkedId){

                case R.id.rb_01:
                    Toast.makeText(RadioButtonAtivity.this, getString(R.string.area01),
                            Toast.LENGTH_SHORT).show();
                    break;

                case R.id.rb_02:
                    Toast.makeText(RadioButtonAtivity.this, getString(R.string.area02),
                            Toast.LENGTH_SHORT).show();
                    break;

                case R.id.rb_03:
                    Toast.makeText(RadioButtonAtivity.this, getString(R.string.area03),
                            Toast.LENGTH_SHORT).show();
                    break;

                case R.id.rb_04:
                    Toast.makeText(RadioButtonAtivity.this, getString(R.string.area04),
                            Toast.LENGTH_SHORT).show();
                    break;


                case R.id.rb_05:
                    Toast.makeText(RadioButtonAtivity.this, getString(R.string.area05),
                            Toast.LENGTH_SHORT).show();
                    break;


                case R.id.rb_06:
                    Toast.makeText(RadioButtonAtivity.this, getString(R.string.area06),
                            Toast.LENGTH_SHORT).show();
                    break;

                case R.id.rb_07:
                    Toast.makeText(RadioButtonAtivity.this, getString(R.string.area07),
                            Toast.LENGTH_SHORT).show();
                    break;

            }

        }
    };






}




 

R.layout.activity_radio_button_ativity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_radio_button_ativity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.choi.mystudy12.RadioButtonAtivity">

    <TextView
        android:text="당신의 고향은?"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/tv_01"
        android:textStyle="normal|bold"
        android:textSize="30sp"
        android:layout_weight="1" />

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/rg_01"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/tv_01">

        <RadioButton
            android:text="@string/area01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb_01"
            android:layout_weight="1"
            />

        <RadioButton
            android:text="@string/area02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb_02"
            android:layout_weight="1" />

        <RadioButton
            android:text="@string/area03"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb_03"
            android:layout_weight="1" />

        <RadioButton
            android:text="@string/area04"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb_04"
            android:layout_weight="1" />

        <RadioButton
            android:text="@string/area05"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb_05"
            android:layout_weight="1" />

        <RadioButton
            android:text="@string/area06"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb_06"
            android:layout_weight="1" />

        <RadioButton
            android:text="@string/area07"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rb_07"
            android:layout_weight="1" />

    </RadioGroup>

</RelativeLayout>

 

 

 

 

 

 

 

 

class ProgressBarActivity
package com.example.choi.mystudy12;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;

public class ProgressBarActivity extends AppCompatActivity {

    private ProgressBar pb_01, pb_02;
    private Button progressBtn, resetBtn, showBtn, hideBtn;



    private Toast toast = null;

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

        pb_01=(ProgressBar)findViewById(R.id.pb_01);
        pb_02=(ProgressBar)findViewById(R.id.pb_02);

        progressBtn=(Button)findViewById(R.id.btn_01);
        resetBtn=(Button)findViewById(R.id.btn_02);
        showBtn=(Button)findViewById(R.id.btn_03);
        hideBtn=(Button)findViewById(R.id.btn_04);

        progressBtn.setOnClickListener(clickListener);
        resetBtn.setOnClickListener(clickListener);
        showBtn.setOnClickListener(clickListener);
        hideBtn.setOnClickListener(clickListener);
    }


    View.OnClickListener clickListener=new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            switch (v.getId()){

                case R.id.btn_01:
                    toastShow("Progress");
                    pb_01.incrementProgressBy(10);
                    pb_01.incrementSecondaryProgressBy(10);
                    break;

                case R.id.btn_02:
                    toastShow("Reset");
                    pb_01.setProgress(0);
                    pb_01.setSecondaryProgress(100);
                    break;

                case R.id.btn_03:
                    toastShow("Show");
                    pb_02.setVisibility(ProgressBar.VISIBLE);
                    break;


                case R.id.btn_04:
                    toastShow("Hide");
                    pb_02.setVisibility(ProgressBar.INVISIBLE);
                    break;

            }
        }
    };



    // 토스트 전용 메서드를 만든다. 따라서 토스트가 하나만 생성된다.
    private void toastShow(String message) {

        // 토스트 메서드

        if (toast == null) {

            toast = Toast.makeText(this, message, Toast.LENGTH_SHORT);

        } else {

            toast.setText(message);

        }

        toast.show();

    }




}

 

R.layout.activity_progress_bar
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_progress_bar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.choi.mystudy12.ProgressBarActivity">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="20dp"
        android:id="@+id/line1"
        >

        <ProgressBar
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/pb_01"
            android:max="200"
            android:progress="50"
            android:secondaryProgress="100" />

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <Button
                android:text="Progress"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/btn_01"
                android:layout_weight="1" />

            <Button
                android:text="Reset"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/btn_02"
                android:layout_weight="1" />
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/line1">

        <ProgressBar
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/pb_02" />

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <Button
                android:text="Show"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/btn_03"
                android:layout_weight="1" />

            <Button
                android:text="Hide"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/btn_04"
                android:layout_weight="1" />
        </LinearLayout>

    </LinearLayout>

</RelativeLayout>

 

 

 

 

 

 

class SeekBarActivity
package com.example.choi.mystudy12;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.Toast;

public class SeekBarActivity extends AppCompatActivity {

    private SeekBar sb=null;
    private Button progressBtn=null;
    private Button resetBtn=null;


    private Toast toast;


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

        sb=(SeekBar)findViewById(R.id.sb_01);
        progressBtn=(Button)findViewById(R.id.bt_01);
        resetBtn=(Button)findViewById(R.id.bt_02);

        progressBtn.setOnClickListener(clickListener);
        resetBtn.setOnClickListener(clickListener);

    }


    View.OnClickListener clickListener=new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            switch (v.getId()){
                case R.id.bt_01:
                    tostShow("Progress");
                    sb.incrementProgressBy(10);
                    sb.incrementSecondaryProgressBy(10);
                    break;

                case R.id.bt_02:
                    tostShow("Reset");
                    sb.setProgress(0);
                    sb.setSecondaryProgress(0);
                    break;
            }
        }
    };


    private void  tostShow(String message){

        if(toast==null){
            toast=Toast.makeText(SeekBarActivity.this, message, Toast.LENGTH_SHORT);
        }else{
            toast.setText(message);
        }

        toast.show();
    }



}

 

R.layout.activity_seek_bar
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_seek_bar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.choi.mystudy12.SeekBarActivity">

    <SeekBar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:id="@+id/sb_01"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_weight="1"
        android:max="200"
        android:progress="50"
        android:secondaryProgress="100"
        />


    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/sb_01"
        >

        <Button
            android:text="Progress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/bt_01"
            android:layout_weight="1" />

        <Button
            android:text="Reset"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/bt_02"
            android:layout_weight="1" />

    </LinearLayout>



</RelativeLayout>

 

 

 

 

 

about author

PHRASE

Level 60  머나먼나라

남녀의 성생활은 이 사람을 떠나지 못하게 하며 자신의 품속에 잡아 두려는 상실(喪失)의 불안함이다. -프란체스코 알베로니

댓글 ( 4)

댓글 남기기

작성