사용하면 좋다...
TextView - OnClick
EditText - .addTextChangeListener(TextWatcher)
CheckBox - .setOnChekcedChangedListener()
RadioGroup - .setOnCheckdChangedListener()
ToggleButton - .setOnChekcedChangedListener()
Button - .setOnClickListener
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@drawable/weather"
    android:id="@+id/ll"
    >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="TextView Demo"
        android:textColor="#ffffff"
        android:textSize="13px"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:autoLink="web|email|phone|map"
        android:text="" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="input your name!"
       
         >
    </EditText>

    <ImageButton
        android:contentDescription="버튼이미지" 
        android:id="@+id/imageButton1"
        android:layout_width="10mm"
        android:layout_height="10mm"
        android:src="@drawable/weather" />

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <ToggleButton
        android:text="토글버튼"
        android:textOn="ON"
        android:textOff="OFF"
        android:id="@+id/toggleButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         />

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="email수신여부" />

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
         >
        <RadioButton
            android:id="@+id/radio0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="남자" />
        <RadioButton
            android:id="@+id/radio1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="여자" />
    </RadioGroup>

</LinearLayout>
package com.gusfree.lisenter2;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.ToggleButton;

public class Lisetner2Activity extends Activity {
	/** Called when the activity is first created. */
	EditText et1;
	TextView tv1;
	TextView tv2;
	ImageButton ib; 
	ToggleButton tb;
	ProgressBar pb;
	CheckBox cb;
	RadioGroup rg;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		et1 = (EditText) findViewById(R.id.editText1);
		tv1 = (TextView) findViewById(R.id.textView1);
		tv2 = (TextView) findViewById(R.id.textView2);
		ib = (ImageButton) this.findViewById(R.id.imageButton1);
		tb = (ToggleButton) findViewById(R.id.toggleButton1);
		pb = (ProgressBar) findViewById(R.id.progressBar1);
		cb = (CheckBox) findViewById(R.id.checkBox1);
		rg = (RadioGroup) findViewById(R.id.radioGroup1);
		// event
		ib.setOnClickListener(new ImageButtonHandler());
		tb.setOnCheckedChangeListener(new ToggleButtonHandler());
		cb.setOnCheckedChangeListener(new CheckBoxHandler());
		rg.setOnCheckedChangeListener(new RadioButtonHandler());
		et1.addTextChangedListener(new EditTextHandler());
		
		
		Resources res=this.getResources();
		String tc=res.getString(R.string.hello);
		tv2.setText(tc);
		 
		
	}
	/*******EditText***************/
	public class EditTextHandler implements TextWatcher{

		public void afterTextChanged(Editable arg0) {
		}

		public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
				int arg3) {
			// TODO Auto-generated method stub
			
		}
		public void onTextChanged(CharSequence arg0, int arg1, int arg2,
				int arg3) {
			tv2.setText(arg0);
			
		}
		
	}
	
	
	/******** RadioGroup *******/
	public class RadioButtonHandler implements
			android.widget.RadioGroup.OnCheckedChangeListener {

		public void onCheckedChanged(RadioGroup group, int checkedId) {
			LinearLayout ll=(LinearLayout)findViewById(R.id.ll);
			if (checkedId == R.id.radio0) {
				// 남자그림배경
				ll.setBackgroundResource(R.drawable.phi);
			} else if (checkedId == R.id.radio1) {
				// 여자그림배경
				ll.setBackgroundResource(R.drawable.iyou);
			}
		}
	}

	/********** CheckBox ****************************/
	public class CheckBoxHandler implements OnCheckedChangeListener {

		public void onCheckedChanged(CompoundButton buttonView,
				boolean isChecked) {
			if (isChecked) {
				buttonView.setText("email수신여부[체크]");
			} else {
				buttonView.setText("email수신여부[안체크]");
			}

		}

	}

	/************ ToggleButton *********************/
	public class ToggleButtonHandler implements OnCheckedChangeListener {

		public void onCheckedChanged(CompoundButton buttonView,
				boolean isChecked) {
			if (isChecked) {
				// progress bar
				pb.setVisibility(View.VISIBLE);
			} else {
				pb.setVisibility(View.INVISIBLE);

			}

		}

	}

	/************* ImageButton ********************/

	public class ImageButtonHandler implements OnClickListener {
		boolean b = false;

		public void onClick(View v) {
			/*
			 * Editable android.widget.EditText.getText()
			 */
			String str = et1.getText().toString();
			tv1.setText(str);
			et1.setText("");
			/** image 변경 **/
			b = !b;
			if (b) {
				ib.setImageResource(R.drawable.weather);
			} else {
				ib.setImageResource(R.drawable.koreanfood);
			}

		}

	}
}



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:id="@+id/layout" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" />

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CheckBox" />

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

        <RadioButton
            android:id="@+id/radio0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="RadioButton" />

        <RadioButton
            android:id="@+id/radio1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RadioButton" />

        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RadioButton" />
    </RadioGroup>

    <ToggleButton
        android:id="@+id/toggleButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ToggleButton" />

</LinearLayout>
package com.listener;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.ToggleButton;

public class ListenerActivity extends Activity {

	LinearLayout layout;
	TextView textView;
	EditText editText;
	CheckBox checkBox;
	RadioGroup radioGroup;
	ToggleButton toggleButton;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		layout=(LinearLayout) findViewById(R.id.layout);
		textView=(TextView) findViewById(R.id.textView1);
		editText = (EditText) this.findViewById(R.id.editText1);
		checkBox = (CheckBox) findViewById(R.id.checkBox1);
		radioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
		toggleButton = (ToggleButton) findViewById(R.id.toggleButton1);
		/*체크박스&토글버튼&라디오그룹 : CheckedChange
		 * 라디오그룹 : ItemSeleced
		 * 텍스트뷰 : ClickListener
		 * layout : ClickListener
		 * editText : addTextWatcher*   */      

		/*리스너 클래스들의 객체를 만들고 
        뷰에 만든 리스너 객체를 셋팅하세요 */
		/*checkBox.setOnCheckedChangeListener(new CheckedChangeListener());
        toggleButton.setOnCheckedChangeListener(new CheckedChangeListener());
        radioGroup.setOnCheckedChangeListener(new RadioListener());
        editText.addTextChangedListener(new EditListener());
        layout.setOnClickListener(new ClickListener());
        textView.setOnClickListener(new ClickListener());*/

		toggleButton.setOnCheckedChangeListener(new T());
		checkBox.setOnCheckedChangeListener(new T());
		radioGroup.setOnCheckedChangeListener(new RG());
		editText.addTextChangedListener(new E());
	}
	class E implements TextWatcher{
		@Override
		public void onTextChanged(CharSequence s, int start, int before,
				int count) {			
			textView.setText(s);
		}
		@Override
		public void afterTextChanged(Editable s) {			
		}
		@Override
		public void beforeTextChanged(CharSequence s, int start, int count,
				int after) {
		}
	}
	class RG implements android.widget.RadioGroup.OnCheckedChangeListener{
		@Override
		public void onCheckedChanged(RadioGroup group, int checkedId) {
			switch(checkedId){
			case R.id.radio0:
				layout.setBackgroundColor(Color.WHITE);
				break;
			case R.id.radio1:
				layout.setBackgroundColor(Color.BLACK);
				break;
			case R.id.radio2:
				layout.setBackgroundColor(Color.GRAY);
				break;
			}
		}
	}
	class T implements OnCheckedChangeListener{

		@Override//토글버튼
		public void onCheckedChanged(CompoundButton buttonView,
				boolean isChecked) {
			if(buttonView==toggleButton){

			}
			if(isChecked){
				layout.setBackgroundResource(R.drawable.sosi);
			}else{
				layout.setBackgroundResource(R.drawable.sosii);
			}

		}

		/*//textView, layout
    class ClickListener implements OnClickListener{

		@Override
		public void onClick(View v) {


		}    	
    }
    //toggleButton, checkBox 용
    class CheckedChangeListener 
    	implements OnCheckedChangeListener{
    	// 개똥이
		@Override
		public void onCheckedChanged(
				CompoundButton buttonView,
				boolean isChecked) {			
		}    	
    }
    //radioGroup 용
    class RadioListener implements 
    android.widget.RadioGroup.OnCheckedChangeListener{
    	//한국의 대구에 사는 개똥이
		@Override
		public void onCheckedChanged(RadioGroup group,
				int checkedId) {
		}
    }
    //editText용 
    class EditListener implements TextWatcher {
		@Override
		public void afterTextChanged(Editable s) {
		}
		@Override
		public void beforeTextChanged(CharSequence s, int start, int count,
				int after) {
		}
		@Override
		public void onTextChanged(CharSequence s, int start, int before,
				int count) {
		}*/
	}
}



<?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" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/dolly" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Large Text"
            android:textColor="#cc0000"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </FrameLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ToggleButton
            android:id="@+id/toogleButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <ToggleButton
            android:id="@+id/toogleButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

</LinearLayout>
package com.gusfree;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToggleButton;

public class LayoutActivity extends Activity 
					implements OnClickListener{
    TextView textView; //클래스 변수 선언
    ImageView imageView;
    ToggleButton toggle1, toggle2;
    
    @Override   
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.frame);
        
        textView=(TextView) findViewById(R.id.textView1);
        imageView = (ImageView) findViewById(R.id.imageView1);
        toggle1=(ToggleButton) findViewById(R.id.toogleButton1);
        toggle2=(ToggleButton) findViewById(R.id.toogleButton2);
       
        toggle1.setOnClickListener(this);
        toggle2.setOnClickListener(this);
        
        MyListener myListener=new MyListener();
        //토글버튼의 Checked가 Change 될때 호출되는 Listener
        toggle1.setOnCheckedChangeListener(myListener);
        toggle2.setOnCheckedChangeListener(myListener);
    } 
    
    class MyListener implements OnCheckedChangeListener{
    	
    	//파라미터1 : 나를 부른뷰.. 파라미터2: 뷰의 체크상태
		@Override
		public void onCheckedChanged(
				CompoundButton v, boolean checked) {
			if(v==toggle1){ 
				if(checked) imageView.setVisibility(View.VISIBLE);
				else imageView.setVisibility(View.GONE);
			}
			// 토글버튼2의 체크상태에 따라 textView가 보였다 안보였다
			else if(v==toggle2){
				if(checked)textView.setVisibility(View.VISIBLE);
				else  textView.setVisibility(View.GONE);
			}
			
		}
    	
    }
    
    /*Listener의 특징 : 파라미터로 리스너를 호출한 뷰가
     * 넘어옵니다     */
	@Override
	public void onClick(View v) {	
		
		/*if(v == toggle1)	{	
			textView.setText("토글버튼1 눌렀다");
			imageView.setVisibility(View.VISIBLE); //static 필드
		}
		else if(v == toggle2){
			textView.setText("토글버튼2 눌렀다");
			imageView.setVisibility(View.INVISIBLE); //static 필드
		}*/
	}
	
	
	
	class A implements OnClickListener{
		
		@Override
		public void onClick(View arg0) {
			
			
		}
		
	}
}







<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:layout_marginBottom="150dp">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/dolly" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="텍스트뷰 텍스트뷰 텍스트뷰 텍스트뷰"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</FrameLayout>



'Android > 2012.04월 강좌' 카테고리의 다른 글

3일차 다양한 이벤트 처리(미완성)  (0) 2012.04.30
3일차 LinearLayout( frame 중복)  (0) 2012.04.30
3일차 Layout3 화면정의  (0) 2012.04.30
3일차 1~45 까지 로또  (0) 2012.04.30
Android review  (0) 2012.04.30


layout-land : 화면을 누워서 출력 하기

layout-port  : 화면을 똑바로 출력 하기



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

    <Button
        android:id="@+id/button1"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/button1"
        android:text="Button" />

    <Button
        android:id="@+id/button3"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/button2"
        android:layout_below="@+id/button1"
        android:layout_marginRight="17dp"
        android:text="Button" />

    <Button
        android:id="@+id/button4"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/button3"
        android:layout_marginLeft="64dp"
        android:layout_toRightOf="@+id/button2"
        android:text="Button" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/button3"
        android:layout_marginTop="39dp"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView1"
        android:layout_alignBottom="@+id/textView1"
        android:layout_alignRight="@+id/button2"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView2"
        android:layout_alignBottom="@+id/textView2"
        android:layout_toRightOf="@+id/textView2"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView3"
        android:layout_alignBottom="@+id/textView3"
        android:layout_toRightOf="@+id/textView3"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView4"
        android:layout_alignBottom="@+id/textView4"
        android:layout_toRightOf="@+id/textView4"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView5"
        android:layout_alignBottom="@+id/textView5"
        android:layout_alignParentRight="true"
        android:text="TextView" />

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1" />

    <ProgressBar
        android:id="@+id/progressBar2"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView2"
        android:layout_alignTop="@+id/progressBar1"
        android:layout_marginTop="59dp" />

    <ProgressBar
        android:id="@+id/progressBar3"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView3"
        android:layout_below="@+id/progressBar1"
        android:layout_marginTop="37dp" />

    <RatingBar
        android:id="@+id/ratingBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/progressBar2"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="35dp" />

    <RatingBar
        android:id="@+id/ratingBar2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/textView3" />

    <ProgressBar
        android:id="@+id/progressBar4"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/ratingBar2"
        android:layout_alignTop="@+id/progressBar1" />
    
</RelativeLayout>


package com.gusfree;

import android.app.Activity;
import android.os.Bundle;

public class LayoutActivity extends Activity {

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



AndroidManifest.xml 에서

화면전환의 설정을  한다...

밑에 Application 선택...


ladscape 는 누운 화면 portrait 똑바른 화면

설정하고 나면 xml 화면에서  자동으로 밑에 화면같이 생성된다

(원래는 적어도 되지만 오타를 방지 위의방법을 추천)  







'Android > 2012.04월 강좌' 카테고리의 다른 글

3일차 LinearLayout( frame 중복)  (0) 2012.04.30
3일차 FrameLayout 중복  (0) 2012.04.30
3일차 1~45 까지 로또  (0) 2012.04.30
Android review  (0) 2012.04.30
2일차 이벤트2  (0) 2012.04.27
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#ff0000"
            android:text="첫번째번호" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#8df220"
            android:text="두번째번호" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#603330"
            android:text="3번째번호" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#0000ff"
            android:text="4번째번호" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#02ff00"
            android:text="5번째번호" />
    </LinearLayout>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="번호 뽑기" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/editText1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:maxLength="2" />

        <EditText
            android:id="@+id/editText2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:maxLength="2" />

        <EditText
            android:id="@+id/editText3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:maxLength="2" />

        <EditText
            android:id="@+id/editText4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:maxLength="2" />

        <EditText
            android:id="@+id/editText5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:maxLength="2" />
    </LinearLayout>

    <TextView
        android:id="@+id/outcome"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>


package com.lotto;

import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class LottoActivity extends Activity {
	TextView tv1,tv2,tv3,tv4,tv5;//로또 추첨번호 뷰
	TextView outcome;
	Button btn1;
	EditText edit1,edit2,edit3,edit4,edit5;

	int[] selects=new int[5];//내가선택한 번호 넣을 배열
	int[] lotto=new int[5];//당첨 번호 배열

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		//클래스 변수의 초기화
		tv1=(TextView) this.findViewById(R.id.textView1);
		tv2=(TextView) this.findViewById(R.id.textView2);
		tv3=(TextView) this.findViewById(R.id.textView3);
		tv4=(TextView) this.findViewById(R.id.textView4);
		tv5=(TextView) this.findViewById(R.id.textView5);
		btn1=(Button) this.findViewById(R.id.button1);
		outcome = (TextView)findViewById(R.id.outcome);

		//사용자가 뽑은 로또번호를 가져오기 위해서
		edit1=(EditText)findViewById(R.id.editText1);
		edit2=(EditText)findViewById(R.id.editText2);
		edit3=(EditText)findViewById(R.id.editText3);
		edit4=(EditText)findViewById(R.id.editText4);
		edit5=(EditText)findViewById(R.id.editText5);
		/* btn1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

			}
		});*/

		MyListener listener = new MyListener();
		btn1.setOnClickListener(listener);
	}
	int count=0;
	Random r=new Random();
	class MyListener implements OnClickListener{

		int ballNumber;//뽑은 번호

		@Override
		public void onClick(View v) {
			//r.nextInt();//랜덤한 int값을 리턴해줍니다.
			//r.nextInt(20);//20이하의 랜덤함 int를 리턴해준다.
			count++;
			ballNumber=r.nextInt(45)+1;
			//중복 안되게 처리하자
			if(count<6){//count가 6일때는 하지 않기
				for(int i=1;i<count;i++){

					if(lotto[i]==ballNumber){//에러 범위
						ballNumber = r.nextInt(45)+1;
						i=0;//처음부터 다시 시작
						Toast.makeText(LottoActivity.this, 
								"중복", 0).show();
						Log.i("중복","중복");
					}
				}
			}
			switch(count){
			case 1:
				lotto[0]=ballNumber;
				tv1.setText(ballNumber+"번");
				break;
			case 2:
				lotto[1]=ballNumber;
				tv2.setText(ballNumber+"번");
				break;
			case 3:
				lotto[2]=ballNumber;
				tv3.setText(ballNumber+"번");
				break;
			case 4:
				lotto[3]=ballNumber;
				tv4.setText(ballNumber+"번");
				break;
			case 5:
				lotto[4]=ballNumber;
				tv5.setText(ballNumber+"번");

				//사용자가 입력한 번호5개 가져와서
				//selects배열에 값넣기

				//Editable ->String
				String no10 = edit1.getText().toString();
				String no20 = edit2.getText().toString();
				String no30 = edit3.getText().toString();
				String no40 = edit4.getText().toString();
				String no50 = edit5.getText().toString();
				//String -> int
				int no1=Integer.parseInt(no10);
				int no2=Integer.parseInt(no20);
				int no3=Integer.parseInt(no30);
				int no4=Integer.parseInt(no40);
				int no5=Integer.parseInt(no50);

				selects[0] = no1;// 내가 뽑은 번호배열 selects
				selects[1] = no2;
				selects[2] = no3;
				selects[3] = no4;
				selects[4] = no5;

				int success=0;

				//selects 내번호와 lotto 당첨 번호를 비교하기
				for(int i=0;i<selects.length;i++){
					for(int j=0;j<lotto.length;j++){
						//selects[0];//내 첫번째 번호
						if(selects[i]==lotto[j]){
							success++;
						}
					}
				}

				outcome.setText(success+"개 맞았다.");

				break;
			default://재도전 하기 구현
				count=0;
				tv1.setText("");
				tv2.setText("");
				tv3.setText("");
				tv4.setText("");
				tv5.setText("");
			}
		}
	}
}  






'Android > 2012.04월 강좌' 카테고리의 다른 글

3일차 FrameLayout 중복  (0) 2012.04.30
3일차 Layout3 화면정의  (0) 2012.04.30
Android review  (0) 2012.04.30
2일차 이벤트2  (0) 2012.04.27
2일차 이벤트  (0) 2012.04.27
/* 설치 : Java  +   android 개발킷 sdk  
 *         이클립스 + 안드로이드 플러그인 (ADT)
 *         버젼별 개발api download
 *         
 *         src(자바소스)   get-R.class   res(자원-xml)
 *         bin 압축되어서 패키지명.apk
 *         
 *         AndroidManifest.xml 관리자 파일
 *         1. 어플아이콘/이름. 버젼. 최초실행될 자바파일
 *         2. 권한 : ...
 *  */

'Android > 2012.04월 강좌' 카테고리의 다른 글

3일차 Layout3 화면정의  (0) 2012.04.30
3일차 1~45 까지 로또  (0) 2012.04.30
2일차 이벤트2  (0) 2012.04.27
2일차 이벤트  (0) 2012.04.27
2일차 Layout2  (0) 2012.04.27


'Android > 개발&Application' 카테고리의 다른 글

예비  (0) 2012.04.28
한글 대탐험 : 안드로이드 어플 개발  (0) 2012.04.28
Project 어플 개발 : U-Alarm  (0) 2012.04.28
성적 관리 앱  (0) 2012.04.28
사칙연산 Spinner와 Radio버튼으로 하기  (0) 2012.04.28


'Android > 개발&Application' 카테고리의 다른 글

예비  (0) 2012.04.28
한글 대탐험 : 안드로이드 어플 개발  (0) 2012.04.28
Project 어플 개발 : U-Alarm  (0) 2012.04.28
성적 관리 앱  (0) 2012.04.28
사칙연산 Spinner와 Radio버튼으로 하기  (0) 2012.04.28


'Android > 개발&Application' 카테고리의 다른 글

예비  (0) 2012.04.28
예비  (0) 2012.04.28
Project 어플 개발 : U-Alarm  (0) 2012.04.28
성적 관리 앱  (0) 2012.04.28
사칙연산 Spinner와 Radio버튼으로 하기  (0) 2012.04.28



'Android > 개발&Application' 카테고리의 다른 글

예비  (0) 2012.04.28
한글 대탐험 : 안드로이드 어플 개발  (0) 2012.04.28
성적 관리 앱  (0) 2012.04.28
사칙연산 Spinner와 Radio버튼으로 하기  (0) 2012.04.28
계산기  (0) 2012.04.28
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" 
	android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<TableLayout 
		android:layout_width="fill_parent" 
		android:layout_height="wrap_content"
		android:stretchColumns="1"
		>
		<TableRow>
			<TextView 
				android:id="@+id/num" 
				android:layout_width="50dp"
				android:layout_height="wrap_content" 
				android:text="번호" />
	
			<TextView
				android:id="@+id/text_num" 
				android:layout_width="fill_parent"
				android:layout_height="wrap_content"
				 />
			</TableRow>
		<TableRow>
			<TextView 
				android:id="@+id/name" 
				android:layout_width="50dp"
				android:layout_height="wrap_content" 
				android:text="이름" />
	
			<EditText
				android:id="@+id/edit_name" 
				android:layout_width="fill_parent"
				android:layout_height="wrap_content"
				 />
			</TableRow>
		<TableRow>
			<TextView 
				android:id="@+id/korean" 
				android:layout_width="50dp"
				android:layout_height="wrap_content" 
				android:text="국어" />
	
			<EditText
				android:id="@+id/edit_korean" 
				android:layout_width="fill_parent"
				android:layout_height="wrap_content" 
				android:inputType="numberDecimal"
				 />
			</TableRow>
		<TableRow>
			<TextView 
				android:id="@+id/english" 
				android:layout_width="50dp"
				android:layout_height="wrap_content" 
				android:text="영어" />
	
			<EditText
				android:id="@+id/edit_english" 
				android:layout_width="fill_parent"
				android:layout_height="wrap_content" 
				android:inputType="numberDecimal"
				 />
			</TableRow>
		<TableRow>
			<TextView 
				android:id="@+id/math" 
				android:layout_width="50dp"
				android:layout_height="wrap_content" 
				android:text="수학" />
	
			<EditText
				android:id="@+id/edit_math" 
				android:layout_width="fill_parent"
				android:layout_height="wrap_content" 
				android:inputType="numberDecimal"
				 />
			</TableRow>
	</TableLayout>
	<LinearLayout
	    android:layout_width="fill_parent" 
		android:layout_height="wrap_content"
		>
		<Button 
				android:id="@+id/add" 
				android:layout_width="fill_parent"
				android:layout_height="wrap_content" 
				android:layout_weight="1"
				android:text="등록"
				 />
		<Button 
				android:id="@+id/modify" 
				android:layout_width="fill_parent"
				android:layout_height="wrap_content" 
				android:layout_weight="1"
				android:text="수정"
				 />
		<Button 
				android:id="@+id/del" 
				android:layout_width="fill_parent"
				android:layout_height="wrap_content" 
				android:layout_weight="1"
				android:text="삭제"
				 />
	</LinearLayout>		 
	<ListView 
		android:id="@android:id/list" 
		android:layout_width="fill_parent"
		android:layout_height="fill_parent"
		android:choiceMode="singleChoice"
		 />
</LinearLayout>


package kr.android.score3;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class Score3 extends ListActivity {


	private static final String SCORE_DATA = "score.txt";
	ArrayList<string> score_items;
	ArrayList<string> items;
	ArrayAdapter<string> adapter;
	EditText name,korean,english,math;
	TextView text;
	int sum, avg, num;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		score_items = new ArrayList<string>();
		items = new ArrayList<string>();

		adapter = 
				new ArrayAdapter<string>(
						this, android.R.layout.simple_list_item_single_choice, items);
				setListAdapter(adapter);

				findViewById(R.id.add).setOnClickListener(mClickListener);
				findViewById(R.id.modify).setOnClickListener(mClickListener);
				findViewById(R.id.del).setOnClickListener(mClickListener);

				text = (TextView)findViewById(R.id.text_num);

				name = (EditText)findViewById(R.id.edit_name);
				korean = (EditText)findViewById(R.id.edit_korean);
				english = (EditText)findViewById(R.id.edit_english);
				math = (EditText)findViewById(R.id.edit_math);
	} 

	public void onResume() {
		super.onResume();

		try {
			InputStream in=openFileInput(SCORE_DATA);

			if (in!=null) {
				InputStreamReader tmp=new InputStreamReader(in);
				BufferedReader reader=new BufferedReader(tmp);
				String str;
				String[] scoredb;

				while ((str = reader.readLine()) != null) {
					scoredb = str.split("\\|");
					score_items.add(str);
					items.add(scoredb[0]+" (총점 : "+scoredb[4]+", 평균 : "+scoredb[5]+")");
				}

				in.close();
			}
		}
		catch (java.io.FileNotFoundException e) {
			// 아직 저장된 내용이 없을 뿐, 문제는 없다.
		}
		catch (Throwable t) {
			Toast
			.makeText(this, "예외: "+t.toString(), 2000)
			.show();
		}
	}


	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		num = position;
		text.setText(position+"");
	}

	public void saveData() {

		try {
			OutputStreamWriter out=
					new OutputStreamWriter(openFileOutput(SCORE_DATA, MODE_PRIVATE));

			StringBuffer sb = new StringBuffer();
			for(String str : score_items){
				sb.append(str+"\n");
			}

			out.write(sb.toString());
			out.close();		
			Toast.makeText(this, "데이터 처리 완료", 4000).show();
		}
		catch (Throwable t) {
			Toast
			.makeText(this, "예외: "+t.toString(), 2000)
			.show();
		}
	}

	public void uiSetChanged(){
		name.setText("");
		korean.setText("");
		english.setText("");
		math.setText("");
		getListView().clearChoices();
		adapter.notifyDataSetChanged();
		saveData();
	}

	Button.OnClickListener mClickListener = new View.OnClickListener() {
		public void onClick(View v) {
			if(v.getId() == R.id.add){

				String name2 = name.getText().toString();
				String korean2 = korean.getText().toString();
				String english2 = english.getText().toString();
				String math2 = math.getText().toString();
				if (name2 !=null && korean2 !=null && english2 !=null && math2 !=null) {
					sum = Integer.parseInt(korean2)+
							Integer.parseInt(english2)+
							Integer.parseInt(math2);
					avg = sum/3;

					score_items.add(0,name2+"|"+korean2+"|"+english2+"|"+math2+"|"+sum+"|"+avg);
					items.add(0,name2+" (총점 : "+sum+",평균 : " + avg + ")");
					uiSetChanged();
				}   
			}else if(v.getId() == R.id.modify){
				String name2 = name.getText().toString();
				String korean2 = korean.getText().toString();
				String english2 = english.getText().toString();
				String math2 = math.getText().toString();
				if (name2 !=null && korean2 !=null && english2 !=null && math2 !=null) {
					sum = Integer.parseInt(korean2)+
							Integer.parseInt(english2)+
							Integer.parseInt(math2);
					avg = sum/3;

				score_items.set(num,name2+"|"+korean2+"|"+english2+"|"+math2+"|"+sum+"|"+avg);
				items.set(num,name2+" (총점 : "+sum+",평균 : " + avg + ")");
				uiSetChanged();
				} 
			}else{
				ListView list = getListView();
				int id=list.getCheckedItemPosition();
				if (id != ListView.INVALID_POSITION) {
					score_items.remove(id);
					items.remove(id);
					uiSetChanged();
				}

			}
		}
	};
	/*
	protected void onPause() {
		super.onPause();
		saveData();
	}
	 */

}




'Android > 개발&Application' 카테고리의 다른 글

예비  (0) 2012.04.28
한글 대탐험 : 안드로이드 어플 개발  (0) 2012.04.28
Project 어플 개발 : U-Alarm  (0) 2012.04.28
사칙연산 Spinner와 Radio버튼으로 하기  (0) 2012.04.28
계산기  (0) 2012.04.28
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="계산기 APP"
        android:textSize="30sp" />

    <EditText
        android:id="@+id/one"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal" />

    <LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_gravity="center" >
    
        <RadioGroup
            android:orientation="horizontal"
        android:id="@+id/RadioGroup01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
        
    <RadioButton
        android:id="@+id/radio1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="+"
        android:textSize="30sp" />
    
    <RadioButton
        android:id="@+id/radio2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="-"
        android:textSize="30sp" />
    
    <RadioButton
        android:id="@+id/radio3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="X"
        android:textSize="30sp" />
    
    <RadioButton
        android:id="@+id/radio4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="÷"
        android:textSize="30sp" />
    </RadioGroup>
    </LinearLayout>

    <EditText
        android:id="@+id/two"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal" />

    <Button
        android:id="@+id/sum"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="계산" />

    <TextView
        android:id="@+id/result"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="결과 : "
        android:textSize="30sp" />

</LinearLayout>


package kr.vichara.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;


public class TestActivity extends Activity {
	int i,j,a1,a2,a3,a4,p;
	String b1;
	TextView result;
	Button sum;
	RadioGroup group;
	EditText one,two;
	RadioButton rb;

	/*public void Process(){
		switch(group.getCheckedRadioButtonId()){
		case R.id.radio1:
			result.setText("결과 : "+(i+j));
			break;
		case R.id.radio2:
			result.setText("결과   : "+(i-j));
			break;
		case R.id.radio3:
			result.setText("결과        : "+(i*j));
			break;
		case R.id.radio4:
			result.setText("결과: "+(i/j));
			break;
		}
	}*/

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		result = (TextView)findViewById(R.id.result);
		sum = (Button)findViewById(R.id.sum);

		one = (EditText)findViewById(R.id.one);
		two = (EditText)findViewById(R.id.two);
		//초기 라디오 선택
		group=(RadioGroup)findViewById(R.id.RadioGroup01);
		group.check(R.id.radio1);

		sum.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v) {
				try{
					i = Integer.parseInt(one.getText()+"");
					j = Integer.parseInt(two.getText()+"");
				}catch(Exception e){
					result.setText("예외 발생");
				}finally{
					switch(group.getCheckedRadioButtonId()){
					case R.id.radio1:
						result.setText("결과 : "+(i+j));
						break;
					case R.id.radio2:
						result.setText("결과   : "+(i-j));
						break;
					case R.id.radio3:
						result.setText("결과        : "+(i*j));
						break;
					case R.id.radio4:
						result.setText("결과: "+(i/j));
						break;
					}
				}
			}
		});
	}
}


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

    
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="사칙연산 계산기 APP"
        android:textSize="30sp" />

    <EditText
        android:id="@+id/one"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal" />

    <TextView
        android:id="@+id/selection"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <Spinner 
        android:id="@+id/spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="50dp"
        android:drawSelectorOnTop="true" />

    <EditText
        android:id="@+id/two"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal" />

    <Button
        android:id="@+id/sum"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="계산" />

    <TextView
        android:id="@+id/result"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="결과 : "
        android:textSize="30sp" />

</LinearLayout>


package kr.vichara.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

public class TestActivity extends Activity implements
AdapterView.OnItemSelectedListener{
	int i, j,p;
	String s;
	TextView selection;
	String[] items = { "+","-","X","÷"};
	TextView result ;
	EditText one,two;
	
	Spinner spin;
	Button sum;


	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		selection = (TextView) findViewById(R.id.selection);

		//이벤트 소스
		spin = (Spinner) findViewById(R.id.spinner);

		//이벤트 소스와 이벤트 리스너가 구현된 객체 연결
		spin.setOnItemSelectedListener(this);

		//어댑터를 이용해 데이터 셋팅
		ArrayAdapter<string> aa = new ArrayAdapter<string>(this,
				android.R.layout.simple_spinner_dropdown_item, items);

		//드롭다운  화면에 표시할 리소스 지정
		aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

		//ArrayAdapter를 Spinner에 등록
		spin.setAdapter(aa);

		sum = (Button) findViewById(R.id.sum);
		
		one = (EditText) findViewById(R.id.one);
		two = (EditText) findViewById(R.id.two);
		result = (TextView) findViewById(R.id.result);
		
		//익명내부클래스로 이벤트리스너
		sum.setOnClickListener(new Button.OnClickListener(){

			public void onClick(View v) {
				try{
					i = Integer.parseInt(one.getText()+"");
					j = Integer.parseInt(two.getText()+"");
				}catch(Exception e){
					result.setText("예외 발생");
				}finally{
					switch((int)spin.getSelectedItemPosition()){
					case 0 :
						result.setText("결과 : "+(i+j));;
						break;
					case 1 :
						result.setText("결과   : "+(i-j));
						break;
					case 2 :
						result.setText("결과        : "+(i*j));
						break;
					case 3 :
						if(i/j<=0){
							result.setText("0보다 작은수로 나눌 수 없습니다");
						}else{
						result.setText("결과: "+(i/j));
						break;
						}
					}
				}
			}
		});
	}

	//이벤트 핸들러
	//전달된 인자
	//AdapterView<!--?--> parent : 이벤트가 발생한 Spinner 객체
	//(제네릭 표현을 써야됨 쓰고싶지 않을때<!--?-->,노란줄이 가더라도 안쓰는것이 좋음) <!--?--> = Object
	//view v : Spinner 하위 객체의 이벤트가 발생한 객체 
	//position : 이벤트가 발생한 위치
	//id : position = id
	public void onItemSelected(AdapterView<!--?--> parent, View v, int position,
			long id) {

	}

	//이벤트 핸들러
	public void onNothingSelected(AdapterView<!--?--> parent) {
		selection.setText("");
	}

}


'Android > 개발&Application' 카테고리의 다른 글

예비  (0) 2012.04.28
한글 대탐험 : 안드로이드 어플 개발  (0) 2012.04.28
Project 어플 개발 : U-Alarm  (0) 2012.04.28
성적 관리 앱  (0) 2012.04.28
계산기  (0) 2012.04.28



Calculation.apk



999TestCalculation.apk




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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="덧셈 계산기 APP"
        android:textSize="30sp" />

    <EditText
        android:id="@+id/one"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="+"
        android:textSize="30sp" />

    <EditText
        android:id="@+id/two"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal" />

    <Button
        android:id="@+id/sum"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="계산" />

    <TextView
        android:id="@+id/result"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="결과 : "
        android:textSize="30sp" />

</LinearLayout>


<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, TestActivity!</string>
    <string name="app_name">Plus Calculation App :-)</string>

</resources>


/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package kr.vichara.test;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int ic_launcher=0x7f020000;
    }
    public static final class id {
        public static final int one=0x7f050000;
        public static final int result=0x7f050003;
        public static final int sum=0x7f050002;
        public static final int two=0x7f050001;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}


package kr.vichara.test;

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

public class TestActivity extends Activity{
	int i, j;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		Button sum = (Button) findViewById(R.id.sum);
		//익명내부클래스로 이벤트리스너
		sum.setOnClickListener(new Button.OnClickListener(){

			public void onClick(View v) {
				TextView result = (TextView) findViewById(R.id.result);
				EditText one = (EditText) findViewById(R.id.one);
				EditText two = (EditText) findViewById(R.id.two);
				try {
					i = Integer.parseInt(one.getText() + "");
					j = Integer.parseInt(two.getText() + "");
				} catch (NumberFormatException e) {
					result.setText("ㅡㅡ");
				} catch (Exception e) {
					result.setText("아 뭐야");
				} finally {
					if(i != 0 && j != 0){
						result.setText("결과 : " + (i + j));
					}else{
						result.setText("입력 하시오");
					}
				}
			}
		});
	}
}


'Android > 개발&Application' 카테고리의 다른 글

예비  (0) 2012.04.28
한글 대탐험 : 안드로이드 어플 개발  (0) 2012.04.28
Project 어플 개발 : U-Alarm  (0) 2012.04.28
성적 관리 앱  (0) 2012.04.28
사칙연산 Spinner와 Radio버튼으로 하기  (0) 2012.04.28


'Android > 기본' 카테고리의 다른 글

Eclipse Phone test  (0) 2012.05.14
Android 9 patch  (0) 2012.05.14
Android 메인로딩 페이지 만들기  (0) 2012.04.28
Android 카메라, 인증키(키스토어)  (0) 2012.04.28
Android surface(마우스에 이미지 따라다니기)  (0) 2012.04.28

+ Recent posts