결과화면

 

 

 package com.example.demo;

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

public class ImageDemo extends Activity {
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.image_demo);
 }
}

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
   
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
       
        <!-- The following four examples use a large image -->
        <!-- 1. Non-scaled view, for reference -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="10dip"
            android:text="@string/image_view_large_normal"/>
        <ImageView
            android:src="@drawable/sample_1"
            android:adjustViewBounds="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
           
        <!-- 2. Limit to at most 50x50 -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="10dip"
            android:text="@string/image_view_large_at_most"/>
        <ImageView
            android:src="@drawable/sample_1"
            android:adjustViewBounds="true"
            android:maxWidth="50dip"
            android:maxHeight="50dip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

       <!-- 3. Limit to at most 70x70, with 10 pixels of padding all around -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="10dip"
            android:text="@string/image_view_large_at_most_padded"/>
       <ImageView
            android:src="@drawable/sample_1"
            android:background="#66FFFFFF"
            android:adjustViewBounds="true"
            android:maxWidth="70dip"
            android:maxHeight="70dip"
            android:padding="10dip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
           
        <!-- 4. Limit to exactly 70x70, with 10 pixels of padding all around -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="10dip"
            android:text="@string/image_view_large_exactly_padded"/>
        <ImageView
            android:src="@drawable/sample_1"
            android:background="#66FFFFFF"
            android:scaleType="centerInside"
            android:padding="10dip"
            android:layout_width="70dip"
            android:layout_height="70dip" />

        <!-- Repeating the previous four examples with small image -->
        <!-- 1. Non-scaled view, for reference -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="10dip"
            android:text="@string/image_view_small_normal"/>
        <ImageView
            android:src="@drawable/stat_happy"
            android:background="#FFFFFFFF"
            android:adjustViewBounds="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
           
        <!-- 2. Limit to at most 50x50 -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="10dip"
            android:text="@string/image_view_small_at_most"/>
        <ImageView
            android:src="@drawable/stat_happy"
            android:background="#FFFFFFFF"
            android:adjustViewBounds="true"
            android:maxWidth="50dip"
            android:maxHeight="50dip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

       <!-- 3. Limit to at most 70x70, with 10 pixels of padding all around -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="10dip"
            android:text="@string/image_view_small_at_most_padded"/>
        <ImageView
            android:src="@drawable/stat_happy"
            android:background="#FFFFFFFF"
            android:adjustViewBounds="true"
            android:maxWidth="70dip"
            android:maxHeight="70dip"
            android:padding="10dip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
           
        <!-- 4. Limit to exactly 70x70, with 10 pixels of padding all around -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="10dip"
            android:text="@string/image_view_small_exactly_padded"/>
        <ImageView
            android:src="@drawable/stat_happy"
            android:background="#FFFFFFFF"
            android:scaleType="centerInside"
            android:padding="10dip"
            android:layout_width="70dip"
            android:layout_height="70dip" />

 
    </LinearLayout>
</ScrollView>

 

아차차!!! String.xml에 다음 코드 추가

 

<string name="image_view_large_normal">Large image at normal size</string>
    <string name="image_view_large_at_most">Large image scaled to at most 50x50</string>
    <string name="image_view_large_at_most_padded">Large image scaled to at most 70x70 with padding</string>
    <string name="image_view_large_exactly_padded">Large image scaled to exactly 70x70 with padding</string>
    <string name="image_view_small_normal">Small image at normal size</string>
    <string name="image_view_small_at_most">Small image scaled to at most 50x50</string>
    <string name="image_view_small_at_most_padded">Small image scaled to at most 70x70 with padding</string>
    <string name="image_view_small_exactly_padded">Small image scaled to exactly 70x70 with padding</string>

'2020년도 이전 > [WebSig] Android' 카테고리의 다른 글

ProgressBar Demo2 -> 원형 프로그레스 바  (0) 2013.08.13
ProgressBar Demo1  (0) 2013.08.13
AutoText Demo 자동완성 텍스트뷰  (0) 2013.08.13
Spinner Demo  (0) 2013.08.13
Button Demo  (0) 2013.08.13

 결과화면

 

 package com.example.demo;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;

public class AutoTextDemo extends Activity {
 String[] items = {"SM3", "SM5", "SM7", "SONATA", "K3", "K5", "K7", "SOUL", "SORENTO"};
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.autotext_demo);
  
  //AutoCompleteTextView - 자동완성 1개만 해줌...
  AutoCompleteTextView auto1 = (AutoCompleteTextView)findViewById(R.id.autotext1);
  auto1.setAdapter(new ArrayAdapter<String>(
    this, android.R.layout.simple_dropdown_item_1line, items
  ));
  
  
  //MultiAutoCompleteTextView - 자동완성 여러개 해줌...
  MultiAutoCompleteTextView auto2 =
    (MultiAutoCompleteTextView)findViewById(R.id.autotext2);
  auto2.setAdapter(new ArrayAdapter<String>(
    this, android.R.layout.simple_dropdown_item_1line, items
  ));
  
  auto2.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
 }
}

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <AutoCompleteTextView
        android:id="@+id/autotext1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:completionHint="pick a item"
        android:completionThreshold="2" />

    <MultiAutoCompleteTextView
        android:id="@+id/autotext2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:completionHint="pick a item"
        android:completionThreshold="2" />

</LinearLayout>

 

'2020년도 이전 > [WebSig] Android' 카테고리의 다른 글

ProgressBar Demo1  (0) 2013.08.13
Image Demo  (0) 2013.08.13
Spinner Demo  (0) 2013.08.13
Button Demo  (0) 2013.08.13
EditText Demo  (0) 2013.08.13

 결과화면

 

//SpinnerDemo.java

 

 package com.example.demo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class SpinnerDemo extends Activity {
 
 void showToast(CharSequence msg){
  Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
 }

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.spinner_demo);
  
  Spinner s1 = (Spinner)findViewById(R.id.spinner1);
  ArrayAdapter<CharSequence> adapter =
    ArrayAdapter.createFromResource(
      this,
      R.array.colors,
      android.R.layout.simple_spinner_item);
  adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  s1.setAdapter(adapter);
  
  s1.setOnItemSelectedListener(new OnItemSelectedListener() {
   public void onItemSelected(AdapterView<?> parent
     , View view, int position, long id){
    showToast("Spinner1 : position=" + position + " id=" + id);
   }
   
   public void onNothingSelected(AdapterView<?> parent){
    showToast("Spinner1 : unselected");
   }
  });
  
  
  
//  Spinner s2 = (Spinner)findViewById(R.id.spinner2);
//  adapter = ArrayAdapter.createFromResource(
//      this,
//      R.array.planets,
//      android.R.layout.simple_spinner_item);
//  adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//  s2.setAdapter(adapter);
//  
//  s2.setOnItemSelectedListener(new OnItemSelectedListener() {
//   public void onItemListener(AdapterView<?> parent
//     , View view, int position, long id){
//    showToast("Spinner2 : position=" + position + " id=" + id);
//   }
//   
//   public void onNothingSelected(AdapterView<?> parent){
//    showToast("Spinner2 : unselected");
//   }
//  });
 }
}

--------------------------------------------------------------------------------------------------

 

//spinner_demo.xml

 

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:padding="10dip"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/spinner_1_color" />

    <Spinner android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:prompt="@string/spinner_1_color_prompt" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dip"
        android:text="@string/spinner_1_planet"  />

    <Spinner android:id="@+id/spinner2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:entries="@array/planets" />

</LinearLayout>

 

 

--------------------------------------------------------------------------------------------------

 

//values폴더 -> arrays.xml 생성..

 

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="colors">
        <item>red</item>
        <item>orange</item>
        <item>yellow</item>
        <item>green</item>
        <item>blue</item>
        <item>violet</item>
    </string-array>
   
    <string-array name="planets">
        <item>Mercury</item>
        <item>Venus</item>
        <item>Earth</item>
        <item>Mars</item>
        <item>Jupiter</item>
        <item>Saturn</item>
        <item>Uranus</item>
        <item>Neptune</item>
        <item>Pluto</item>
    </string-array>
</resources>

 

 

String.xml에 다음 코드 추가~~~

 

<string name="spinner_1_color">Color:</string>
    <string name="spinner_1_planet">Planet:</string>
    <string name="spinner_1_color_prompt">Choose a color</string>
   
    <string name="spinner_1_planet_prompt">Choose a planet</string>

'2020년도 이전 > [WebSig] Android' 카테고리의 다른 글

Image Demo  (0) 2013.08.13
AutoText Demo 자동완성 텍스트뷰  (0) 2013.08.13
Button Demo  (0) 2013.08.13
EditText Demo  (0) 2013.08.13
TextView Demo  (0) 2013.08.13

 결과화면

 

 package com.example.demo;

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

public class MainActivity extends Activity {

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

--------------------------------------------------------------------------------------------------

 

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

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

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

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

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

    <ToggleButton
        android:id="@+id/toggleButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ToggleButton"
        android:textOn="textOn"
        android:textOff="textOff" />
   
    <Switch
        android:id="@+id/switch1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Switch"
        android:textOn="textOn"
        android:textOff="textOff"
        android:checked="true"/>

    <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
            android:id="@+id/radio1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="짬뽕" />
       
        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="콩국수" />
    </RadioGroup>

</LinearLayout>

 

결과화면

 

-------------------------------------------------------------------------------------------------------

 

EditTextDemo.java

 

 package com.example.demo;

import android.app.Activity;
import android.os.Bundle;
import android.text.InputFilter;
import android.widget.EditText;

public class EditTextDemo extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.edit_demo);
  
  EditText text_filtered = (EditText)findViewById(R.id.input_filered);
  text_filtered.setFilters(new InputFilter[] {
   new InputFilter.AllCaps(),         //소문자로 입력된 값을 대문자로 바꿔줌
   new InputFilter.LengthFilter(2)   //최대 2글자만 입력가능..
  });
 }
}

 

--------------------------------------------------------------------------------------------------

 

edit_demo.xml

 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/linear02"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="type here"
            android:lines="4" />            //4줄까지만 보임...

 

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="preset value"
            android:editable="false" />               //내용을 바꿀수 없음...
        
        <EditText
            android:id="@+id/input_filered"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="type here" />
       
        <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="숫자만 입력 가능합니다"
            android:inputType="number" />                 //숫자만 입력 가능함...

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="비밀번호를 입력하세요"
            android:password="true" />                     //비밀번호 입력 EditText
        
    </LinearLayout>

</ScrollView>

 

결과화면

 

 TextViewDemo.java

 

package com.example.demo;

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

public class TextViewDemo extends Activity {

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

 

--------------------------------------------------------------------------------------------------

 

tv_demo.xml

 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

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

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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:autoLink="all"
            android:linksClickable="false"
            android:text="@string/autolink_test" />

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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:autoLink="all"
            android:linksClickable="true"
            android:text="@string/autolink_test" />

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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/ell_test" />
       
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/dash" />
       
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/ell_test"
            android:singleLine="true" />

    </LinearLayout>

</ScrollView>

 

--------------------------------------------------------------------------------------------------

 

string.xml

 

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

    <string name="app_name">Day2</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
    <string name="autolink_test">This is a test. My blog is at
        http://androidbook.blogspot.com\nEmail me at
        test@gmail.com\nCall me at (800) 555-1212\nFind me at my favorite coffee joint
        1456 White Mountain Hwy, North Conway, NH 03860</string>
    <string name="ell_test">Word supercallafragalisticexpealadocious.</string>
    <string name="dash">---------------------------------------------------------------</string>

</resources>

 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

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

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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:autoLink="all"
            android:linksClickable="false"
            android:text="@string/autolink_test" />

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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:autoLink="all"
            android:linksClickable="true"
            android:text="@string/autolink_test" />

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

    </LinearLayout>

</ScrollView>

'2020년도 이전 > temp' 카테고리의 다른 글

html5 - 4번 예제  (1) 2013.08.30
joinProcessServlet.java  (0) 2013.08.01
joinDAO.java  (0) 2013.08.01
join_confirm --- 수정중!!  (0) 2013.07.31
서블릿 -- LoginServlet.java  (0) 2013.07.31

결과화면

 

 

 

 

IntentCaller.java

 

 package com.example.hellow;

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

public class IntentCaller extends Activity{
 public static final int CALLER_REQUEST = 100;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.caller);
  
  Button send = (Button)findViewById(R.id.send);
  send.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
    EditText uname = (EditText)findViewById(R.id.userName);
    EditText byear = (EditText)findViewById(R.id.birthYear);
    
    //명시적 인텐트 생성
    Intent intent = new Intent(IntentCaller.this, IntentCallee.class);
    intent.putExtra("name", uname.getText());
    intent.putExtra("birth", byear.getText());
    startActivityForResult(intent, CALLER_REQUEST);
   }
  });
 }//onCreate() end

 //IntentCallee.class에서 데이터를 받고나서 받은 데이터를 이용하는 메서드
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  if(CALLER_REQUEST == requestCode){
   if(resultCode==Activity.RESULT_OK){
    String name = data.getExtras().getString("name").toString();
    String age = data.getExtras().get("age").toString();
    
    TextView result = (TextView)findViewById(R.id.txtAge);
    result.setText(name + "의 나이는 " + age + "입니다.");
   }
  }
 }
}

 

--------------------------------------------------------------------------------------------------

 

caller.xml

 

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

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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="이름 : " />

        <EditText
            android:id="@+id/userName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <requestFocus />
        </EditText>
    </LinearLayout>

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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="태어난 년도 : " />

        <EditText
            android:id="@+id/birthYear"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="1989"
            android:inputType="number" />
    </LinearLayout>

    <Button
        android:id="@+id/send"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="나이 계산하기" />

    <TextView
        android:id="@+id/txtAge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:textColor="#0000ff"
        android:textSize="15sp"/>

</LinearLayout>

 

--------------------------------------------------------------------------------------------------------

 

IntentCallee.java

 

 package com.example.hellow;

import java.util.Calendar;

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

public class IntentCallee extends Activity{
 TextView txtName, txtBitrh;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.callee);
  
  txtName = (TextView)findViewById(R.id.txt_name);
  txtBitrh = (TextView)findViewById(R.id.txt_birth);
  
  Intent intent = getIntent();
  String name = intent.getExtras().get("name").toString();
  String birth = intent.getExtras().get("birth").toString();
  
  txtName.setText(name);
  txtBitrh.setText(birth);
  
  Button result = (Button)findViewById(R.id.ok);
  result.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
    Calendar now = Calendar.getInstance();
    int nowYear = now.get(Calendar.YEAR) + 1;
    int age = nowYear - Integer.parseInt(txtBitrh.getText().toString());
    Intent intent = new Intent(IntentCallee.this, IntentCaller.class);
    intent.putExtra("name", txtName.getText().toString());
    intent.putExtra("age", String.valueOf(age));
    setResult(Activity.RESULT_OK, intent);
    finish();
   }
  });
 }
}

 

--------------------------------------------------------------------------------------------------

 

callee.xml

 

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

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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="이름 : " />

        <TextView
            android:id="@+id/txt_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="태어난 년도 : " />

        <TextView
            android:id="@+id/txt_birth"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <Button
        android:id="@+id/ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="결과 보내기" />

</LinearLayout>

 

 

'2020년도 이전 > [WebSig] Android' 카테고리의 다른 글

Button Demo  (0) 2013.08.13
EditText Demo  (0) 2013.08.13
TextView Demo  (0) 2013.08.13
암시적 Intent 사용 예제  (0) 2013.08.13
BroadcastReceiver 예제...  (0) 2013.08.12

+ Recent posts