Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 메소드
- 생성자
- Menu
- 에러페이지
- Graphic
- oracle
- 오버로딩
- JSP
- 기본
- HTML
- 클래스
- layout
- 메서드
- 배열
- 안드로이드
- Spring
- paint
- 국제화
- OGNL
- JavaScript
- 어노테이션
- 전화걸기
- Eclips
- 예외처리
- Android
- 이클립스
- mybatis
- struts2
- Java
- AWT
Archives
- Today
- Total
note
성적 관리 앱 본문
<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1" > <TextView android:gravity="center" android:id="@+id/num" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TableRow> <TextView android:padding="10dp" android:text="이름 : " android:textSize="30sp" /> <EditText android:id="@+id/name" android:padding="10dp" android:singleLine="true" android:hint="이름 입력" /> </TableRow> <TableRow> <TextView android:padding="10dp" android:text="국어 : " android:textSize="30sp" /> <EditText android:id="@+id/korean" android:inputType="numberDecimal" android:padding="10dp" android:singleLine="true" /> </TableRow> <TableRow> <TextView android:padding="10dp" android:text="영어 : " android:textSize="30sp" /> <EditText android:id="@+id/english" android:inputType="numberDecimal" android:padding="10dp" android:singleLine="true" /> </TableRow> <TableRow> <TextView android:padding="10dp" android:text="수학 : " android:textSize="30sp" /> <EditText android:id="@+id/math" android:inputType="numberDecimal" android:padding="10dp" android:singleLine="true" /> </TableRow> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal" > <Button android:id="@+id/add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="추가" android:textSize="30sp" /> <Button android:id="@+id/mod" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="수정" android:textSize="30sp" /> <Button android:id="@+id/del" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="삭제" android:textSize="30sp" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout> </TableLayout>
package kr.vichara.grade;
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 Homework_grade extends ListActivity {
int a1, a2, a3, avg, add1,p,mode;
String name2, add2, avg2;
Button add, mod, del;
EditText korean, english, math, name;
TextView num;
String[] items;
ArrayList list;
ArrayAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
num = (TextView) findViewById(R.id.num);
add = (Button) findViewById(R.id.add);
mod = (Button) findViewById(R.id.mod);
del = (Button) findViewById(R.id.del);
korean = (EditText) findViewById(R.id.korean);
english = (EditText) findViewById(R.id.english);
name = (EditText) findViewById(R.id.name);
math = (EditText) findViewById(R.id.math);
list = new ArrayList();
//추가
add.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
if(R.id.add == v.getId()){
mode=v.getId();
Process();
String b[] = { "이름 : ", name.getText().toString(),
" 총점 : ", add2, " 평균 : ", avg2 };
list.add(0, b[0] + b[1] + b[2] + b[3] + b[4] + b[5]);
Clear();
}
}
});
//수정
mod.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
if(R.id.mod == v.getId()){
if(name != null && korean != null && english != null && math != null){
mode=v.getId();
Process();
String b[] = { "이름 : ", name.getText().toString(),
" 총점 : ", add2, " 평균 : ", avg2 };
list.set(p, b[0] + b[1] + b[2] + b[3] + b[4] + b[5]);
Clear();
}else{
num.setText("수정 값을 입력하세요");
}
}
}
});
//삭제
del.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
if(R.id.del == v.getId()){
mode=v.getId();
Process();
list.remove(p);
Clear();
}
}
});
//아답터 생성 싱글초이스로 하나만 선택(반대는멀티초이스)
adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_single_choice, list);
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
//클릭되어지는
public void onListItemClick(ListView parent, View v, int position, long id) {
p = position;
num.setText("선택된 번호 : " + p + " 번");
}
public void Clear(){
//초기화
name.setText("");
korean.setText("");
english.setText("");
math.setText("");
//출력
setListAdapter(adapter);
}
public void Process(){
//공통부분
try {
a1 = Integer.parseInt(korean.getText() + "");
a2 = Integer.parseInt(english.getText() + "");
a3 = Integer.parseInt(math.getText() + "");
name2 = name.getText().toString();
add1 = a1 + a2 + a3;
avg = add1 / 3;
add2 = Integer.toString(add1);
avg2 = Integer.toString(avg);
} catch (Exception e) {
num.setText("예외 발생");
} finally {
Message();
}
}
public void Message(){
switch(mode){
case R.id.add:
Toast.makeText(this,p+" 번에 저장 되었습니다",4000).show();
break;
case R.id.mod:
Toast.makeText(this,p+" 번이 수정 되었습니다",4000).show();
break;
case R.id.del:
Toast.makeText(this,p+" 번이 삭제 되었습니다",4000).show();
break;
}
}
}
'개발노트' 카테고리의 다른 글
성적관리3(파일 저장사용) (0) | 2012.01.18 |
---|---|
성적관리 앱2 (0) | 2012.01.15 |
안드로이드 성적관리 아이콘 (0) | 2012.01.11 |
사칙연산 Spinner와 Radio버튼으로 하기 (0) | 2012.01.10 |
계산기 (0) | 2012.01.07 |