'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

+ Recent posts