지난 포스팅에 이은 내용입니다. 참고로 "Android 고객등록/정보전달 01" 게시글을 참조하신 후 본 포스팅을 확인해주세요. 이어지는 내용입니다^^
이 글이 도움이 되신다면 로그인 필요없이, 추천 버튼 한번 클릭 부탁드립니다^^
알찬 정보로 보답할게요~
First.java(main Activity)
package com.example.formadvlabcustomer;
import java.util.Calendar;
import android.os.Bundle;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Dialog;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
public class First extends Activity {
private TextView mDateDisplay;
private int mYear;
private int mMonth;
private int mDay;
static final int DATE_DIALOG_ID=0;
Spinner spinner;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayAdapter<CharSequence> adapter =
ArrayAdapter.createFromResource(this, R.array.interest_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner = (Spinner) findViewById(R.id.spinner_interest);
spinner.setAdapter(adapter);
mDateDisplay = (TextView) findViewById(R.id.edit_birthday);
mDateDisplay.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(DATE_DIALOG_ID);
}
});
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
updateDisplay();
}//end
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener,mYear, mMonth, mDay);
}
return null;
}//end
private DatePickerDialog.OnDateSetListener mDateSetListener =
new DatePickerDialog.OnDateSetListener(){
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth){
mYear = year ;
mMonth = monthOfYear ;
mDay = dayOfMonth ;
updateDisplay();
}
};
private void updateDisplay() {
mDateDisplay.setText(
new StringBuilder()
.append(mYear).append("-")
.append(mMonth+1).append("-")
.append(mDay).append(" ")
);
}//end
public void onClick(View v){
//성명추출
EditText et_name = (EditText)findViewById(R.id.edit_name);
String str_name = et_name.getText().toString();
//성별추출
RadioGroup rg_sex = (RadioGroup)findViewById(R.id.radiogroup_sex);
RadioButton rb_male = (RadioButton)findViewById(R.id.radio_male);
RadioButton rb_female = (RadioButton)findViewById(R.id.radio_female);
String str_sex = "";
if(rg_sex.getCheckedRadioButtonId() == R.id.radio_male){
str_sex = rb_male.getText().toString();
}
if(rg_sex.getCheckedRadioButtonId() == R.id.radio_female){
str_sex = rb_female.getText().toString();
}
//수신여부 추출
CheckBox chk_sms = (CheckBox)findViewById(R.id.checkbox_sms);
String str_sms = "";
if(chk_sms.isChecked()){
str_sms = (String) chk_sms.getText();
}
//관심분야 추출
String str_interest = spinner.getSelectedItem().toString();
//생일 추출
EditText et_birthday = (EditText)findViewById(R.id.edit_birthday);
String str_birthday = et_birthday.getText().toString();
//호출할 클래스 지정
Intent it = new Intent(this, First.class);
//전송할 정보를 인턴트에 저장
it.putExtra("it_name", str_name);
it.putExtra("it_sex", str_sex);
it.putExtra("it_sms", str_sms);
it.putExtra("it_interest", str_interest);
it.putExtra("it_birthday", str_birthday);
//호출할 클래스를 액티비티로 실행
startActivity(it);
//현재 액티비티 종료
finish();
}//onClick end
}//class END
receive.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<!-- 제목 수평 배치 -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<!-- 제목 -->
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="@string/title_receive"
/>
</LinearLayout>
<!-- 성명 수평 배치 -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<!-- 성명 라벨 -->
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="@string/name"
/>
<!-- 성명 수신 내용 -->
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:id="@+id/tv_name"
/>
</LinearLayout>
<!-- 성별 수평 배치 -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<!-- 성별 라벨 -->
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="@string/sex"
/>
<!-- 성별 수신 내용 -->
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:id="@+id/sex"
/>
</LinearLayout>
<!-- 수신여부 수평배치 -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<!-- 수신여부 라벨 -->
<TextView
android:layout_width="60sp"
android:layout_height="wrap_content"
android:text="@string/receive"
/>
<!-- 수신여부 내용 -->
<TextView
android:layout_width="60sp"
android:layout_height="wrap_content"
android:id="@+id/tv_receive"
/>
</LinearLayout>
<!-- 관심여부 수평배치 -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<!-- 관심여부 라벨 -->
<TextView
android:layout_width="60sp"
android:layout_height="wrap_content"
android:text="@string/interest"
/>
<!-- 관심여부 내용 -->
<TextView
android:layout_width="60sp"
android:layout_height="wrap_content"
android:id="@+id/tv_interest"
/>
</LinearLayout>
<!-- 생일에 대한 수평배치 -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<!-- 생일에 대한 라벨 -->
<TextView
android:layout_width="60sp"
android:layout_height="wrap_content"
android:text="@string/birthday"
/>
<!-- 생일에 대한 내용 -->
<TextView
android:layout_width="60sp"
android:layout_height="wrap_content"
android:id="@+id/tv_birthday"
/>
</LinearLayout>
<!-- "이전"버튼 수평배치 -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right"
>
<!-- 버튼 오른쪽으로 -->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="before"
/>
</LinearLayout>
</LinearLayout>
CustomerInfoActivity.java
package com.example.formadvlabcustomer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class CustomerInfoActivity extends Activity implements OnClickListener {
public void onCreate(Bundle bun){
//액티비티 생성
super.onCreate(bun);
//receive.xml 레이아웃
setContentView(R.layout.receive);
//정보추출을 위한 인텐트를 생성합니다.
Intent it = getIntent();
//인텐트로부터 정보를 추출합니다.
String str_name = it.getStringExtra("it_name");
String str_sex = it.getStringExtra("it_sex");
String str_sms = it.getStringExtra("it_sms");
String str_interest = it.getStringExtra("it_interest");
String str_birthday = it.getStringExtra("it_birthday");
////추출 정보출력
//성명
TextView tv_name = (TextView)findViewById(R.id.tv_name);
tv_name.setText(str_name);
//성별
TextView tv_sex = (TextView)findViewById(R.id.tv_sex);
tv_name.setText(str_sex);
//sms 수신
TextView tv_sms = (TextView)findViewById(R.id.tv_receive);
tv_name.setText(str_sms);
//관심분야(spinner)
TextView tv_interest = (TextView)findViewById(R.id.tv_interest);
tv_name.setText(str_interest);
//생일
TextView tv_birthday = (TextView)findViewById(R.id.tv_birthday);
tv_name.setText(str_birthday);
//"이전"버튼 클릭
Button btn = (Button)findViewById(R.id.button_prev);
btn.setOnClickListener(this);
}//onCreacre end
@Override
public void onClick(View v) {
//호출 액티비티
Intent it = new Intent(this, CustomerInfoActivity.class);
//호출 액티비티 실행
startActivity(it);
//종료
finish();
}//onClick end
}//class END
androidMainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.formadvlabcustomer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.formadvlabcustomer.First"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
//아래의 액티비티가 추가되었습니다.
<activity
android:name="com.example.CustomerInforActivity"
android:label="@string/act_name_receive" >
</activity>
</application>
</manifest>
고객등록 액티비티에서 고객정보를 입력 ===> 전송 클릭 ==> 고객정보 액티비티에서 입력된 정보를 수신==> 출력 ==> 이전 버튼 클릭 ==> 고객등록 화면으로 다시 이동
전체 싸이클은 위와 같습니다.
'IT > Android' 카테고리의 다른 글
안드로이드 SQLite DB 활용한 고객등록과 조회 3-2 (0) | 2013.07.19 |
---|---|
안드로이드 SQLite DB 활용한 고객등록과 조회 3-1 (0) | 2013.07.18 |
WebView / 웹 문서 / 웹 뷰 (0) | 2013.07.16 |
Android(안드로이드) 웹서버 (0) | 2013.07.15 |
Android 고객등록/정보전달 01 (0) | 2013.07.12 |