专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Android

Android初学 急求为何?该怎么解决

发布时间:2010-05-30 10:53:35 文章来源:www.iduyao.cn 采编人员:星星草
Android初学 急求为何?
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);
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: