2013. 1. 14. 11:53ㆍMobile/Android
.java
public class ggari_JuminbonhoActivity extends Activity {
/** Called when the activity is first created. */
EditText et1;
EditText et2;
EditText result1;
TextView tv1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
et1 = (EditText) findViewById(R.id.et1);
et2 = (EditText) findViewById(R.id.et2);
if (!(et1.getText().length()==6)){
Toast.makeText(getApplicationContext(),"앞자리 6자리 숫자를 정확하게 입력해라", 1).show();
return;
}else if (!(et2.getText().length()==7)){
Toast.makeText(getApplicationContext(),"뒷자리 7자리 숫자를 정확하게 입력해라", 1).show();
return;
} // 앞 , 뒤 민번 정확하게 입력했는지 판단
result1 = (EditText) findViewById(R.id.result1);
String text = et1.getText().toString()+ et2.getText().toString();
Vector vdata = new Vector();
for (int i = 0; i < text.length(); i++) {
vdata.add(Integer.parseInt(text.substring(i, i + 1)));
}
int sum = 0;
int[] multipliers = { 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5 };
for (int i = 0; i < vdata.size() - 1; i++) {
sum += (((Integer) vdata.get(i)).intValue() * multipliers[i]);
}
int lastnum = ((11 - (sum % 11)) % 10);
int result = et2.getText().charAt(6) - 48;
System.out.println(result);
TextView tv1 = (TextView) findViewById(R.id.tv1);
tv1.setText(et1.getText().toString()+" - "+ et2.getText().toString());
if (lastnum == result) {
result1.setText("민번이있다 넌누구냐.");
} else {
result1.setText("민번없다 ㅠㅠ");
}
et1.setText("");
et2.setText("");
}
});
}
}
main.xml
<?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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/et1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number"
android:maxLength="6"
android:hint="주민번호 앞자리" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:text="-" />
<EditText
android:id="@+id/et2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number"
android:maxLength="7"
android:hint="주민번호 뒷자리" />
</LinearLayout>
<Button
android:id="@+id/btn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="검사하기" />
<TextView
android:id="@+id/tv1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" />
<EditText
android:id="@+id/result1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
/>
</LinearLayout>
'Mobile > Android' 카테고리의 다른 글
[안드로이드,Android] map 주소 가저오기 (0) | 2013.01.14 |
---|---|
[안드로이드,android]Map apiKey 값 얻기 (0) | 2013.01.14 |
안드로이드 네트워크 확인 방법 (실시간) (0) | 2013.01.11 |
Google Analytics , Google Analytics for Android (0) | 2013.01.07 |
[안드로이드,Android] 3자리수(세자리마다) , 컴마 찍기 천단위 금액 , 컴마찍기 (1) | 2013.01.04 |