Ffi Activity Activity

SMffift^ffiMffi ' ^AA^T-i Activity Wii^iB ° ftffiWMW Affii Activity A^ ' Activity 0

1. ' sifiKS^IiSffiTSi

package com.misoo.ex12;

import android.app.Activity;

import android.content.Intent;

import android.graphics.Color;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.LinearLayout;

public class ex12 extends Activity {

private final int WC = LinearLayout.LayoutParams. WRAP_CONTENT;

private LinearLayout layout;

private LinearLayout.LayoutParams para;

static final int RGREQUEST = 0;

private int mColor = Color. YELLOW;

@Override public void onCreate(Bundle icicle) {

super.onCreate(icicle); layout = new LinearLayout(this); layout.setOrientation(LinearLayout. VERTICAL); para = new LinearLayout.LayoutParams(230, 140); Draw View dv = new DrawView(this); layout.addView(dv, para);

Button btn = new Button(this);

btn.setText("Change Color"); btn.setOnClickListener(listener); para = new LinearLayout.LayoutParams(WC, WC); layout.addView(btn, para); setContentView(lay out);

public int getColor() { return mColor; } private OnClickListener listener = new OnClickListener() { public void onClick(View v) {

Intent in = new Intent(ex12.this, rgActivity. class); startActivityForResult(in, RGREQUEST);

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == RG REQUEST) { if (resultCode == RESULTCANCELED)

setTitle("Canceled..."); else if(resultCode == RESULT OK) {

String data_str = (String)data.getCharSequenceExtra("DataKey"); setTitle(data_str);

if(data_str.contains("Y")) mColor = Color. YELLOW; else mColor = Color.BLUE;

Step-3: MM Activity lAAS^ : rgActivity ' AgA®®T : // — rgActivity.java gA®

package com.misoo.ex12; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.RadioButton;

import android.widget.RadioGroup;

import android.widget.RadioGroup.OnCheckedChangeListener;

public class rgActivity extends Activity implements OnCheckedChangeListener{ private final int WC = RadioGroup.LayoutParams. WRAP_CONTENT; private RadioGroup rg_layout; RadioGroup.LayoutParams params; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); rg_layout = new RadioGroup(this); params = new RadioGroup.LayoutParams(WC, WC); rg_layout.setOrientation(RadioGroup. VERTICAL); rg_lay out. setLay outParams(params); rg_lay out. setOnCheckedChangeListener(this);

RadioButton button1 = new RadioButton(this); button1.setText("Yellow"); button1.setId(1001); params = new RadioGroup.LayoutParams(WC, WC); rg_lay out. addView(button1,params);

RadioButton button2 = new RadioButton(this); button2.setText("Blue"); button2.setId(1002); params = new RadioGroup.LayoutParams(WC, WC); rg_lay out. addView(button2,params); setContentView(rg_lay out);

public void onCheckedChanged(RadioGroup arg0, int arg1) { String cc;

if(arg0.getCheckedRadioButtonId() == 1001) cc = "Y"; else cc = "B";

Bundle bundle = new Bundle(); bundle.putString("DataKey", cc); Intent mIntent = new Intent(); mIntent.putExtras(bundle); setResult(RESULT_OK, mIntent); finish();

package com.misoo.ex12; import android.content.Context;

import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.view.View;

public class DrawView extends View { private Paint pa; private Context ctx; public DrawView(Context context) { super(context);

ctx = context; pa = new Paint(); } @Override protected void onDraw(Canvas canvas) { ex12 obj = (ex12)ctx;

pa.setColor(obj.getColor()); canvas.drawRect(10, 10, 100, 100, pa); pa.setColor(Color. GREEN); pa.setStrokeWidth(4); pa.setStrokeCap(Paint. Cap.ROUND);

canvas.drawLine(10, 55, 100, 55, pa); canvas.drawLine(55, 10, 55, 100, pa);

pa.setColor(Color.RED);

1. fcm&nftmm Activity : ex12 > MMSX ex12 = ^

2. ^T<Change Color>®ffi^ ' g^M^W onClickO®» :

public void onClick(View v) {

Intent in = new Intent(ex12.this, rgActivity.class); startActivityForResult(in,RG_RE0UES7);

startActivityForResult ()H# ' ff^MT rgActivity T ° MXSPMMM rgActivity ° ft^M^WMffl RadioButton ^Zlfi- =

3. MMZ.& ' rgActivity ^ft onCheckedChanged()M :

public void onCheckedChanged(RadioGroup arg0, int arg1) { String cc;

if(arg0.getCheckedRadioButtonId() == 1001) cc = "Y"; else cc = "B";

Bundle bundle = new Bundle(); bundle.putString("DataKey", cc);

Intent mIntent = new Intent();

mlntent.putExtras(bundle);

setResult(RESULT_OK, mIntent);

protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == RG REQUEST) { if (resultCode == RESULTCANCELED) setTitle("Canceled..."); else if(resultCode == RESULT OK) {

String data_str = (String)data.getCharSequenceExtra("DataKey"); setTitle(data_str);

if(data_str.contains("Y")) mColor = Color. YELLOW; else mColor = Color. BLUE;

X rgActivity ' MAffiMAtA ' rlfflj

* mmmmm Activity • • mMmmmr-m • m mmmmmmy ° ♦

Misoo mrnmumm^i^m?

TEL: (02) 2739-8367 E-mail: [email protected]

TEL: (02) 2739-8367 E-mail: [email protected]

TEL: 400-886-0806 E-mail: [email protected] com

0m Java a C/C++m^gmmmm^mm > rn^ftrnrnxm > m^mm

2. Android g^SfttfriMM^Object-Oriented Application Framework)

3. Java fttfri^mmS. Android MB

4. C/C^fttfri^mma Android MB

5. Android

0 0

Post a comment