Android 爱好调查页面
来源:互联网 发布:java语言与basic 编辑:程序博客网 时间:2024/05/18 03:03
使用工具 Android studio
首先贴一下
layout的代码
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"><TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="你喜欢的运动是什么?点击下方按钮"/> <CheckBox android:id="@+id/CbBasketball" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="篮球" /> <CheckBox android:id="@+id/CbPingpangball" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="乒乓球" /> <CheckBox android:id="@+id/Cblittleball" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="小球"/> <CheckBox android:id="@+id/Cbcoolball" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="冰球"/> <CheckBox android:id="@+id/CbFootball" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="足球" /> <CheckBox android:id="@+id/badminton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="羽毛球"/> <TextView android:id="@+id/TvResult" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/str" /></LinearLayout>
main部分代码
package com.sqlite.exam.agreepage;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.TextView;public class MainActivity extends AppCompatActivity { private CheckBox CbBaskball; //定义篮球的复选框对象 private CheckBox CbPingpangball; //定义乒乓球的复选框对象 private CheckBox CbFootball; //定义足球的复选框对象 private CheckBox Cblittleball; //定义小球的复选框 private CheckBox Cbcoolball; //冰球 private CheckBox badminton; //羽毛球 private TextView TvResult; //定义结果文本便签对象 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findView(); //获取页面中的控件 setListener(); //设置控件的监听器 } private void setListener() { //设置所有CheckBox的状态改变监听器 CbBaskball.setOnCheckedChangeListener(myCheckChanglistener); CbPingpangball.setOnCheckedChangeListener(myCheckChanglistener); CbFootball.setOnCheckedChangeListener(myCheckChanglistener); Cblittleball.setOnCheckedChangeListener(myCheckChanglistener); Cbcoolball.setOnCheckedChangeListener(myCheckChanglistener); badminton.setOnCheckedChangeListener(myCheckChanglistener); } CompoundButton.OnCheckedChangeListener myCheckChanglistener = new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { setText(); } }; private void findView() { //通过findView得到对应的控件对象 CbBaskball= (CheckBox)findViewById(R.id.CbBasketball); CbPingpangball =(CheckBox)findViewById(R.id.CbPingpangball); CbFootball =(CheckBox)findViewById(R.id.CbFootball); TvResult =(TextView)findViewById(R.id.TvResult); Cblittleball = (CheckBox)findViewById(R.id.Cblittleball); Cbcoolball = (CheckBox)findViewById(R.id.Cbcoolball); badminton = (CheckBox)findViewById(R.id.badminton); } private void setText() { String str; TvResult.setText(""); //清空TextView的内容 //如果CbBasketball被选中,则加入TvResult内容显示 if(CbBaskball.isChecked()){ str = TvResult.getText().toString()+CbBaskball.getText().toString()+","; TvResult.setText(str); } if (CbPingpangball.isChecked()) { str = TvResult.getText().toString()+CbPingpangball.getText().toString()+","; TvResult.setText(str); } if(CbFootball.isChecked()) { str = TvResult.getText().toString()+CbFootball.getText().toString()+","; TvResult.setText(str); } if(Cblittleball.isChecked()) { str = TvResult.getText().toString()+Cblittleball.getText().toString()+","; TvResult.setText(str); } if (Cbcoolball.isChecked()) { str = TvResult.getText().toString()+Cbcoolball.getText().toString()+","; TvResult.setText(str); } if(badminton.isChecked()) { str = TvResult.getText().toString()+badminton.getText().toString(); TvResult.setText(str); } }}string部分代码
<resources> <string name="app_name">agreepage</string> <string name="str"></string></resources>
最后完成代码范例。
阅读全文
0 0
- Android 爱好调查页面
- 爱好
- android应用需求调查
- Android Itext调查文档
- Android调查问卷
- 调查...
- 调查
- 记录用户信息的jsp页面(包含对于爱好和出生日期的js)
- 爱好转移
- java爱好
- 篮球爱好
- 测试爱好
- jsp实现对一个网站页面调查的表单
- 调查称谷歌Android手机用户占用最多网络流量
- PC与Android间通信相关调查
- Android NavigationBar中虚拟键调查
- Android NavigationBar中虚拟键调查
- android 实现调查问卷-单选-多选
- Firefox-57.0b8 编译日志
- Spring Boot属性文件application.properties配置文档(全部)
- Xilinx FPGA 学习笔记——时钟资源
- Lucene-基础篇
- 《TensorFlow实战实例》的一些错误更正ValueError: Only call `sparse_softmax_cross_entropy_with_logits` with named a
- Android 爱好调查页面
- Qt问题记录之cannot include corecrt.h
- radio
- Unity相机随游戏对象的移动而移动及调整大小
- JVM
- STL list基本实现
- HTTP协议基础(一)
- Java-笔记3
- HDU4871-Shortest-path tree