感觉今天所学的 radio listcheckbox spinner 基础内容都比较简单

目前只写了单选的信息显示。

checkBox 和 Spinner 还没实现

源码如下

(注意要写第二个Activity的清单

即添加Activity02的activity标签)


Activity01Activity

package yzy.cxt.com;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;


public class Activity01Activity extends Activity {


// 定义控件变量
private RadioButton radioButton01;
private RadioButton radioButton02;
private CheckBox cb1;
private CheckBox cb2;
private CheckBox cb3;
private CheckBox cb4;
private EditText editText;
private Button button;



@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.one_layout);


// 绑定变量
radioButton01 = (RadioButton) findViewById(R.id.radiobutton01);
radioButton02 = (RadioButton) findViewById(R.id.radiobutton02);
cb1 = (CheckBox) findViewById(R.id.cb1);
cb2 = (CheckBox) findViewById(R.id.cb2);
cb3 = (CheckBox) findViewById(R.id.cb3);
cb4 = (CheckBox) findViewById(R.id.cb4);
editText = (EditText) findViewById(R.id.edit);
button = (Button) findViewById(R.id.button);


// 为radioButton01设置监听事件
radioButton01.setOnCheckedChangeListener(new OnCheckedChangeListener() {


@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
radioButton01.setChecked(isChecked);
if (radioButton02.isChecked()) {
radioButton02.setChecked(false);
}
}


});


// 为radioButton02设置监听事件
radioButton02.setOnCheckedChangeListener(new OnCheckedChangeListener() {


@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
radioButton02.setChecked(isChecked);
if (radioButton01.isChecked()) {
radioButton01.setChecked(false);
}
}


});


// 为Button设置监听事件
button.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View arg0) {
String quantityType = "";
String descri = "";
String db = "";
// 获取信息
if (radioButton01.isChecked() && !radioButton02.isChecked()) {
quantityType = "twenty";
} else if (radioButton02.isChecked()
&& !radioButton01.isChecked()) {
quantityType = "thirty";
} else {
Toast.makeText(Activity01Activity.this, "请正确选择",
Toast.LENGTH_LONG);
}




descri = editText.getText().toString();


// 将信息放入Bundle
Bundle bundle = new Bundle();
bundle.putString("quantityType", quantityType);
bundle.putString("desc", descri);



Intent intent = new Intent();
intent.setClass(Activity01Activity.this, Activity02.class);
intent.putExtras(bundle);


// 开始。。。。跳转
startActivity(intent);
}


});
}

}



Activity02

package yzy.cxt.com;


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


public class Activity02 extends Activity{


private TextView message;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.two_layout);

Bundle bundle = this.getIntent().getExtras();
String quantity = "";
// 接收信息并显示
message = (TextView)findViewById(R.id.message);
String quantityType = bundle.getString("quantityType");
String desc = bundle.getString("desc");

// 判断
if ("twenty".equals(quantityType)) {
quantity = "20";
} else {
quantity = "30";
}

message.setText("你选择的每页帖数是" + quantity + ", 您对本站的看法为:" + desc);
}


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


<LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
Android:orientation="vertical"
Android:layout_width="fill_parent"
Android:layout_height="fill_parent"
>
<TextView
Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:text="界面风格"
Android:textSize="20px" />


<Spinner
Android:id="@+id/styleSp"
Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:entries="@array/style"
Android:prompt="@string/style_prompt" />
<TextView
Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:text="提醒"
Android:textSize="20px" />


<CheckBox
Android:id="@+id/cb1"
Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:text="私人消息" />
<CheckBox
Android:id="@+id/cb2"
Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:text="公共消息" />
<CheckBox
Android:id="@+id/cb3"
Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:text="论坛任务" />
<CheckBox
Android:id="@+id/cb4"
Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:text="系统消息"/>
<TextView
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:textSize="20sp"
Android:layout_marginLeft="30px"
Android:layout_marginRight="30px"
Android:text="每页帖数"
/>
<RadioButton
Android:id="@+id/radiobutton01"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:text="20"
/>
<RadioButton
Android:id="@+id/radiobutton02"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:text="30"
/>
<TextView
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:textSize="20sp"
Android:text="您对本站的看法"
/>
<EditText
Android:id="@+id/edit"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:textSize="20px"
Android:width="200sp"
/>
<Button
Android:id="@+id/button"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:text="提交"
/>
</LinearLayout>

two_layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
Android:orientation="vertical"
Android:layout_width="fill_parent"
Android:layout_height="fill_parent"
>
<TextView
Android:id="@+id/message"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
/>
</LinearLayout>






更多相关文章

  1. 【转】【Android】获取手机中已安装apk文件信息(PackageInfo、Re
  2. android 信息(mms)的故事(五)-- 发彩信
  3. coredump在Android上的应用
  4. Android(安卓)通过无线调试
  5. Android实现可复用的筛选页面
  6. 【android】消息传递利器EventBus的使用
  7. Android(安卓)Studio 修改默认作者信息和可用的模板
  8. android手机修改系统分变率/修改机型/系统属性等信息
  9. *video标签在微信公众号上出现的一些问题*

随机推荐

  1. Linux学习之Vi和Vim区别是什么?
  2. AndroidStudio 优秀的第三方数据库 Green
  3. AndroidLinearLayout:添加阴影边界Linear
  4. flutter 持久化存储-----数据库sqflite
  5. Drawable和Bitmap转换
  6. Android触摸事件分发之View篇
  7. android使用AIDL跨进程通信(IPC)
  8. 第五章 网络 之 Android网络知识&框架(二)
  9. 解决CardView在5.0以下留白的问题
  10. 干货丨高频数据处理技巧:如何将高频信号转