1.Activity使用方法(跳转):

(1)写Activity类继承Activity

package com.example.test2;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener; public class SecondActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_activity);
} }

 (2)写布局文件

<?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" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="this is second activity"
/> </LinearLayout>

(3) AndroidManifest.xml注册Activity

(4)MainActivity中通过一个按钮的点击事件引出第二个Activity

全部代码:

package com.example.test2;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener; public class MainActivity extends Activity implements OnCheckedChangeListener { private Button login_button;
private Button reset;
private RadioGroup rg;
private Button other;
private CheckBox checkBox1;
private Button myButton; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_radiobutton); rg = (RadioGroup) this.findViewById(R.id.radioGroup1);
rg.setOnCheckedChangeListener(this); Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this,SecondActivity.class);
MainActivity.this.startActivity(intent);
}
}); } @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} @Override
public void onCheckedChanged(RadioGroup arg0, int checkId) {
// TODO Auto-generated method stub
switch(checkId){
case R.id.radio0:
Log.i("tag", "当前选中男");
break ;
case R.id.radio1:
Log.i("tag", "当前选中女");
break ;
default:
break ;
}
} }

 (5)效果:

最新文章

  1. strstr函数的用法
  2. [MySQL Reference Manual] 5 MySQL 服务管理
  3. php大力力 [045节] 兄弟连高洛峰 PHP教程 2014年[已发布,点击下载]
  4. 练习PYTHON之GEVENT
  5. 数据库性能优化一:SQL索引一步到位
  6. 一篇详细的 Mysql Explain 详解
  7. Big Number(大数)
  8. OpenGL------显示列表
  9. CCF考试认证模拟练习——数字排序
  10. 讲述Sagit.Framework解决:双向引用导致的IOS内存泄漏(中)- IOS不为人知的Bug
  11. eclipse报错
  12. jquery中prop()和attr()用法
  13. linux添加自定义命令
  14. Okhttp、Volley和Gson的简单介绍和配合使用
  15. 对pandas和pendulum的吐槽——TimeStamp numpy的datetime64的转型问题
  16. 【转】Skynet之消息队列 - 消息的存储与分发
  17. id不连续
  18. jQuery .load() 里面的代码不能执行
  19. 0_Simple__simpleStreams
  20. [Android Pro] Android中IntentService的原理及使用

热门文章

  1. 搭建一个简单的dns缓存服务器
  2. mybatis在where中比较复杂的判断
  3. [Codeforces976E]Well played!(贪心)
  4. SpringMVC文件上传——bean的配置【org.springframework.web.multipart.commons.CommonsMultipartResolver】
  5. is 和 == 的区别,utf和gbk的转换,join用法
  6. 获取IMSI
  7. 为什么rows这么大,在mysql explain中---写在去acumg听讲座的前一夜
  8. 《Cracking the Coding Interview》——第16章:线程与锁——题目4
  9. CodeIgniter学习笔记四:CI中的URL相关函数,路由,伪静态,去掉index.php
  10. 【Max Points on a Line 】cpp