package com.misoo.ex01;
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 Ex01 extends Activity
{
private final int WC = LinearLayout.LayoutParams.WRAP_CONTENT;
private LinearLayout layout;
private int mColor = Color.YELLOW;
private LinearLayout.LayoutParams lParams;
static final int RG_REQUEST = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
lParams = new LinearLayout.LayoutParams(230, 140);
DrawView drawView= new DrawView(this);
layout.addView(drawView, lParams);
Button button = new Button(this);
button.setText("Change Color");
button.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
Intent intent = new Intent(Ex01.this, RgActivity.class);
startActivityForResult(intent, RG_REQUEST);
}
});
lParams = new LinearLayout.LayoutParams(WC, WC);
layout.addView(button, lParams);
setContentView(layout);
}
public int getColor()
{
return mColor;
}
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data)
{
if (requestCode == RG_REQUEST)
{
if (resultCode == RESULT_CANCELED)
{
setTitle("Canceled...");
}
else if (resultCode == RESULT_OK)
{
String dataString = (String) data.getCharSequenceExtra("DataKey");
setTitle(dataString);
if (dataString.contains("Y"))
{
mColor = Color.YELLOW;
}
else
{
mColor = Color.BLUE;
}
}
}
}
}
package com.misoo.ex01;
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 radioGroup;
RadioGroup.LayoutParams rParams;
@Override
public void onCreate(Bundle bundle)
{
super.onCreate(bundle);
radioGroup = new RadioGroup(this);
rParams = new RadioGroup.LayoutParams(WC, WC);
radioGroup.setOrientation(RadioGroup.VERTICAL);
radioGroup.setLayoutParams(rParams);
radioGroup.setOnCheckedChangeListener(this);
RadioButton radioButton = new RadioButton(this);
radioButton.setText("Yellow");
radioButton.setId(1001);
rParams = new RadioGroup.LayoutParams(WC, WC);
radioGroup.addView(radioButton, rParams);
RadioButton radioButton1 = new RadioButton(this);
radioButton1.setText("Blue");
radioButton1.setId(1002);