-
wxpython问卷调查界面_自己做的一个简单的问卷调查系统
2020-12-08 09:16:25疫情期间,先来没事做,就简单的用ssm 写了一个问卷调查系统。用于我们学校得青协调查用。这就是我做得一个首页的页面,首页做的比较简单嘻嘻。因为刚接触ssm 框架,我首先的思路是先把整体的ssm框架都搭建好,再去...疫情期间,先来没事做,就简单的用ssm 写了一个问卷调查系统。用于我们学校得青协调查用。
这就是我做得一个首页的页面,首页做的比较简单嘻嘻。
因为刚接触ssm 框架,我首先的思路是先把整体的ssm框架都搭建好,再去写具体的代码。
所以我在这里也不多说了,直接上代码:
pom.xml也都是按着网上教程一点点走的,
pom.xml
4.0.0
cn.huapei
queston_ssm
1.0-SNAPSHOT
war
queston_ssm Maven Webapp
http://www.example.com
UTF-8
UTF-8
4.2.5.RELEASE
3.2.8
5.1.29
1.7.18
1.2.17
jstl
jstl
1.2
javax
javaee-api
7.0
junit
junit
4.11
test
org.springframework
spring-core
${spring.version}
org.springframework
spring-web
${spring.version}
org.springframework
spring-oxm
${spring.version}
org.springframework
spring-tx
${spring.version}
org.springframework
spring-jdbc
${spring.version}
org.springframework
spring-webmvc
${spring.version}
org.springframework
spring-context
${spring.version}
org.springframework
spring-context-support
${spring.version}
org.springframework
spring-aop
${spring.version}
org.springframework
spring-test
${spring.version}
org.mybatis
mybatis
${mybatis.version}
org.mybatis
mybatis-spring
1.2.2
mysql
mysql-connector-java
${mysql-driver.version}
commons-dbcp
commons-dbcp
1.2.2
com.alibaba
fastjson
1.1.41
log4j
log4j
${log4j.version}
org.slf4j
slf4j-api
${slf4j.version}
org.slf4j
slf4j-log4j12
${slf4j.version}
org.codehaus.jackson
jackson-mapper-asl
1.9.13
com.fasterxml.jackson.core
jackson-core
2.8.0
com.fasterxml.jackson.core
jackson-databind
2.8.0
commons-fileupload
commons-fileupload
1.3.1
commons-io
commons-io
2.4
commons-codec
commons-codec
1.9
com.google.code.gson
gson
2.8.0
web-ssm
org.apache.maven.plugins
maven-compiler-plugin
6
6
resources 里的文件如下:
jdbc.properties:
driverClasss=com.mysql.jdbc.Driver
jdbcUrl=jdbc:mysql://localhost:3306/yijian?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
username=root
password=123456
#定义初始连接数
initialSize=0
#定义最大连接数
maxActive=20
#定义最大空闲
maxIdle=20
#定义最小空闲
minIdle=1
#定义最长等待时间
maxWait=60000
log4j.properties
添加log4j的日志文件
log4j.rootLogger=INFO,Console,File
#控制台日志
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=System.out
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%p][%t][%d{yyyy-MM-dd HH\:mm\:ss}][%C] - %m%n
#普通文件日志
log4j.appender.File=org.apache.log4j.RollingFileAppender
log4j.appender.File.File=logs/ssm.log
log4j.appender.File.MaxFileSize=10MB
#输出日志,如果换成DEBUG表示输出DEBUG以上级别日志
log4j.appender.File.Threshold=ALL
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern=[%p][%t][%d{yyyy-MM-dd HH\:mm\:ss}][%C] - %m%n
spring-mvc.xml
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
text/html;charset=UTF-8
spring-mybatis.xml
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
这是利用mybatis 实现对数据库的操作。
/p>
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
insert into question(question,a, b ,c,d,type) values (
#{questions.question},#{questions.a},#{questions.b}
,#{questions.c},#{questions.d},#{questions.type}
)
select * from question;
insert into feedback(qu_id, question, daan,q_type)
select #{feedback.qu_id},#{feedback.question},#{feedback.daan},#{feedback.q_type}
from dual
where not exists (
select qu_id from feedback
where daan = #{feedback.daan} )
select * from feedback;
update feedback set num_daan=num_daan+1
where daan=#{daan}
delete from question where q_id=#{id}
delete from feedback where qu_id=#{id}
这个是我的数据库 代码:
/*SQLyog Professional v12.08 (64 bit)
MySQL - 5.5.19 : Database - yijian
**********************************************************************/
/*!40101 SET NAMES utf8*/;/*!40101 SET SQL_MODE=''*/;/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0*/;/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0*/;/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO'*/;/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0*/;CREATE DATABASE /*!32312 IF NOT EXISTS*/`yijian` /*!40100 DEFAULT CHARACTER SET utf8*/;USE`yijian`;/*Table structure for table `feedback`*/
DROP TABLE IF EXISTS`feedback`;CREATE TABLE`feedback` (
`fb_id`int(10) NOT NULL AUTO_INCREMENT COMMENT '反馈id',
`qu_id`int(10) DEFAULT NULL COMMENT '问题id',
`question`varchar(100) DEFAULT NULL COMMENT '问题题目',
`daan`varchar(100) DEFAULT NULL COMMENT '问题答案',
`q_type`int(1) DEFAULT NULL COMMENT '问题类型id',
`num_daan`int(100) DEFAULT '1' COMMENT '回答问题数量',PRIMARY KEY(`fb_id`),KEY`qu_id` (`qu_id`),KEY`q_type` (`q_type`),CONSTRAINT `feedback_ibfk_1` FOREIGN KEY (`qu_id`) REFERENCES`question` (`q_id`),CONSTRAINT `feedback_ibfk_2` FOREIGN KEY (`q_type`) REFERENCES`q_type` (`type_id`)
) ENGINE=InnoDB AUTO_INCREMENT=70 DEFAULT CHARSET=utf8;/*Data for the table `feedback`*/
insert into `feedback`(`fb_id`,`qu_id`,`question`,`daan`,`q_type`,`num_daan`) values (54,1,'请问您在校青协身','副部长',1,13),(55,1,'请问您在校青协身份是','部长',1,17),(57,3,'青协哪点让你欣赏?','制度严明,职位职位清晰',2,16),(59,3,'青协哪点让你欣赏?','职位职位清晰',2,13),(61,34,'你的留言','你好这是留言',3,1),(62,34,'你的留言','你好这是留言1',3,1),(63,34,'你的留言','你好这是留言2',3,1),(64,2,'您进入青协至今多长时间','2',1,1),(65,3,'青协哪点让你欣赏?','制度严明,职位职位清晰,制度清晰,作事有意义',2,1),(66,34,'你的留言','青协很不错,加油继续干',3,0),(67,2,'您进入青协至今多长时间','4',1,1),(68,34,'你的留言','这是我写的',3,1);/*Table structure for table `q_type`*/
DROP TABLE IF EXISTS`q_type`;CREATE TABLE`q_type` (
`type_id`int(4) NOT NULLAUTO_INCREMENT,
`type_name`varchar(25) DEFAULT NULL,PRIMARY KEY(`type_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;/*Data for the table `q_type`*/
insert into `q_type`(`type_id`,`type_name`) values (1,'单选'),(2,'多选'),(3,'填空');/*Table structure for table `question`*/
DROP TABLE IF EXISTS`question`;CREATE TABLE`question` (
`q_id`int(25) NOT NULL AUTO_INCREMENT COMMENT '问题id',
`question`varchar(50) DEFAULT NULL COMMENT '问题',
`a`varchar(50) DEFAULT NULL COMMENT 'a选项',
`b`varchar(50) DEFAULT NULL,
`c`varchar(50) DEFAULT NULL,
`d`varchar(50) DEFAULT NULL,
`type`int(4) DEFAULT NULL,PRIMARY KEY(`q_id`),KEY`type` (`type`),CONSTRAINT `question_ibfk_1` FOREIGN KEY (`type`) REFERENCES`q_type` (`type_id`)
) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=utf8;/*Data for the table `question`*/
insert into `question`(`q_id`,`question`,`a`,`b`,`c`,`d`,`type`) values (1,'请问您在校青协身份是','部长','副部长','干事','会员',1),(2,'您进入青协至今多长时间','1','2','3','4',1),(3,'青协哪点让你欣赏?','制度严明','职位职位清晰','制度清晰','作事有意义',2),(34,'你的留言',NULL,NULL,NULL,NULL,3);/*!40101 SET SQL_MODE=@OLD_SQL_MODE*/;/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS*/;/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS*/;/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES*/;
最后是我们的web.xml
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version="3.0">
web-ssm
contextConfigLocation
classpath:spring-mybatis.xml
log4jConfigLocation
classpath:log4j.properties
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
encodingFilter
/*
org.springframework.web.context.ContextLoaderListener
org.springframework.web.util.IntrospectorCleanupListener
SpringMVC
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring-mvc.xml
1
true
SpringMVC
/
/index.jsp
15
现在已经把 框架建立完成,万事具备,就差逻辑代码
首先我们先看实体类:
实体类我定义了两个,一个反馈, 一个问题实体。
如下:
反馈:
packagecn.huapei.model;importjava.util.List;public classfeedback {private intfb_id;private intqu_id;privateString question;privateString daan;private intq_type;private intnum_daan;private Listfeedbacks;
@OverridepublicString toString() {return "feedback{" +
"fb_id=" + fb_id +
", qu_id=" + qu_id +
", question='" + question + '\'' +
", daan='" + daan + '\'' +
", q_type=" + q_type +
", num_daan=" + num_daan +
", feedbacks=" + feedbacks +
'}';
}public intgetNum_daan() {returnnum_daan;
}public void setNum_daan(intnum_daan) {this.num_daan =num_daan;
}public intgetQ_type() {returnq_type;
}public void setQ_type(intq_type) {this.q_type =q_type;
}public intgetFb_id() {returnfb_id;
}public void setFb_id(intfb_id) {this.fb_id =fb_id;
}publicString getQuestion() {returnquestion;
}public voidsetQuestion(String question) {this.question =question;
}publicString getDaan() {returndaan;
}public voidsetDaan(String daan) {this.daan =daan;
}public ListgetFeedbacks() {returnfeedbacks;
}public void setFeedbacks(Listfeedbacks) {this.feedbacks =feedbacks;
}public intgetQu_id() {returnqu_id;
}public void setQu_id(intqu_id) {this.qu_id =qu_id;
}
}
问题:
packagecn.huapei.model;importjava.util.List;public classquestion {privateInteger q_id;privateString question;privateString a;privateString b;privateString c;privateString d;privateInteger type;private Listquestions ;
@OverridepublicString toString() {return "question{" +
"q_id=" + q_id +
", question='" + question + '\'' +
", a='" + a + '\'' +
", b='" + b + '\'' +
", c='" + c + '\'' +
", d='" + d + '\'' +
", type=" + type +
'}';
}public intgetQ_id() {returnq_id;
}public void setQ_id(intq_id) {this.q_id =q_id;
}publicString getQuestion() {returnquestion;
}public voidsetQuestion(String question) {this.question =question;
}publicString getA() {returna;
}public voidsetA(String a) {this.a =a;
}publicString getB() {returnb;
}public voidsetB(String b) {this.b =b;
}publicString getC() {returnc;
}public voidsetC(String c) {this.c =c;
}publicString getD() {returnd;
}public voidsetD(String d) {this.d =d;
}public intgetType() {returntype;
}public void setType(inttype) {this.type =type;
}public ListgetQuestions() {returnquestions;
}public void setQuestions(Listquestions) {this.questions =questions;
}
}
接着我们创建我们dao和service
dao
packagecn.huapei.dao;importcn.huapei.model.feedback;importcn.huapei.model.question;importorg.apache.ibatis.annotations.Param;importorg.springframework.stereotype.Repository;importjava.util.List;
@Repository("QuestionDao")public interfaceQuestionDao {//创建问题列表
public int inserQuestion(@Param("questions") question questions);public ListgetAllQuestions();public int insertFeedback(@Param("feedback") feedback feedback);public ListgetAllFeedback();public int updateNum(@Param("daan") String daan);//通过id 删除问题
public int delQuestionByid(@Param("id") intid);//通过问题id 删除反馈
public int delFeedbackByid(@Param("id") intid);
}
service
packagecn.huapei.service;importcn.huapei.model.feedback;importcn.huapei.model.question;importjava.util.List;public interfaceQuestionService {//创建问题列表
public int inserQuestion( Listquestions);public ListgetAllQuestions();public intinsertFeedback(feedback feedback);//输出问卷调查结果
public Listjieguoshuchu();//通过id 删除问题
public int delQuestionByid( intid);
}
service实现类
packagecn.huapei.service.impl;importcn.huapei.dao.QuestionDao;importcn.huapei.model.feedback;importcn.huapei.model.question;importcn.huapei.service.QuestionService;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Service;importorg.springframework.transaction.annotation.Transactional;importjava.util.List;
@Service("QuestionService")
@Transactionalpublic class QuestionServiceImpl implementsQuestionService {
@AutowiredprivateQuestionDao questionDao ;public int inserQuestion(Listquestions) {int i = 0;try{for(question q:questions) {
i+=questionDao.inserQuestion(q);
}
}catch(Exception ex){
System.out.println(ex);
}
System.out.println("Service"+i);returni;
}public ListgetAllQuestions() {returnquestionDao.getAllQuestions();
}public intinsertFeedback(feedback feedback) {int i = 0;int s = 0;try{if (feedback.getQ_type()==1||feedback.getQ_type()==2){
String daan=feedback.getDaan();
i+=questionDao.updateNum(daan);
System.out.println("更新》》》》"+i+"条数据");
}
s=questionDao.insertFeedback(feedback);
System.out.println("添加》》》》"+s+"条数据");
}catch(Exception ex){
System.err.println(ex);
}if(s==0){returni;
}else{returns;
}
}
@Overridepublic Listjieguoshuchu() {returnquestionDao.getAllFeedback();
}
@Overridepublic int delQuestionByid(intid) {int i= 0;try{
List allFeedback =questionDao.getAllFeedback();for(feedback f : allFeedback){if(f.getQu_id() ==id){
questionDao.delFeedbackByid(id);break;
}
}
i=questionDao.delQuestionByid(id);
System.out.println("service"+i);
}catch(Exception ex){
System.err.println(ex);
}returni;
}
}
最后是我们的控制层 :
packagecn.huapei.controller;importcn.huapei.model.feedback;importcn.huapei.model.question;importcn.huapei.service.QuestionService;importcom.google.gson.Gson;importcom.google.gson.GsonBuilder;importcom.google.gson.reflect.TypeToken;importorg.springframework.stereotype.Controller;importorg.springframework.ui.Model;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.RequestParam;importorg.springframework.web.bind.annotation.ResponseBody;importjavax.annotation.Resource;importjavax.servlet.http.HttpServletRequest;importjava.util.ArrayList;importjava.util.List;
@Controllerpublic classQuestionController {//@Autowired
@ResourceprivateQuestionService questionService;
@RequestMapping("/chuangjian")
@ResponseBodypublicString inserQuestion(String jsons, HttpServletRequest request) {
System.out.println(jsons);
Gson gson= newGsonBuilder().create();
List list = gson.fromJson(jsons, new TypeToken>() {
}.getType());
System.out.println("---->listJsonStr convert List " +list);int i =questionService.inserQuestion(list);
System.out.println(i);if (i > 0) {return "true";
}else{return "false";
}
}
@RequestMapping("/getQuestion")publicString getAllQuestions(Model model) {
List allQuestions =questionService.getAllQuestions();
System.out.println("所有的问题列表——---------》" +allQuestions);
model.addAttribute("questions", allQuestions);return "wenjuan";
}
@RequestMapping("/question_jg")
@ResponseBodypublicString feedbacks(feedback feedback) {
System.out.println("返回集合》》》》" +feedback);
List feedbacks =feedback.getFeedbacks();
System.out.println("反馈》》》》》》" +feedbacks);int i = 0;for(feedback f : feedbacks) {
System.out.println(f);
i=questionService.insertFeedback(f);
}
System.out.println(i);if (i > 0) {return "true";
}else{return "false";
}
}
@RequestMapping("/Results_page")publicString Results(Model model) {
List feedbackList =questionService.jieguoshuchu();
List allQuestions =questionService.getAllQuestions();
model.addAttribute("feedbackList", feedbackList);
model.addAttribute("allQuestions", allQuestions);return "list";
}//跳转问题页面。。。。
@RequestMapping("createqu")publicString create() {return "createqution";
}//跳转管理页面
@RequestMapping("/managementpage")publicString managementPage(Model model) {
List allQuestions =questionService.getAllQuestions();
model.addAttribute("allQuestions", allQuestions);return "management";
}//管理问题
@RequestMapping("/management")
@ResponseBodypublic String Wjmanagement(@RequestParam(value = "id",required = false) String id) {
Integer del_Id=Integer.parseInt(id);
System.out.println(del_Id);int i =questionService.delQuestionByid(del_Id);
System.out.println(i);if (i > 0) {return "true";
}else{return "false";
}
}
}
最后是我们的前端页面这里jsp 我使用了简单的Bootstrap 前端框架进行美化。
我们首页的jsp
controller.jsp
Created by IntelliJ IDEA.
User: 99573
Date: 2020/2/27
Time: 20:25
To change this template use File | Settings | File Templates.
--%>
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
中心控制页面你好,世界! 欢迎来到我的调查问卷系统。
创建
问卷
结果查询
问卷管理
创建--%>
创建2--%>
问卷 --%>
结果查询--%>
$(function () {
$(".wenjuan").click(function () {
location.assign("getQuestion")
})
$(".jieguo").click(function () {
location.assign("Results_page")
})
$(".chuangjian").click(function () {
location.assign("createqu")
})
$(".createqutions").click(function () {
location.assign("createqu")
})
$(".guanli").click(function () {
location.assign("managementpage")
})
})
创建问题页面
createqution.jsp
User:99573
Date:2020/2/24
Time:14:38
Tochange this template use File | Settings | File Templates.--%>
Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>
调查问卷创建页面css/quesstionnair.css"type="text/css">
单选
多选
填空
单选
-
一个简单的问卷调查服务端设计
2021-01-18 14:58:56最近遇到个需求需要设计个问卷调查,包括发布问卷、选择题型、提交问卷、统计选择题的选项概率,所以就简单设计了下。(备注:无题库概念) 1、数据库设计 问卷信息表 DROP TABLE IF EXISTS `t_survey_info`; ...最近遇到个需求需要设计个问卷调查,包括发布问卷、选择题型、提交问卷、统计选择题的选项概率,所以就简单设计了下。(备注:无题库概念)
1、数据库设计
问卷信息表
DROP TABLE IF EXISTS `t_survey_info`;
CREATE TABLE `t_survey_info` (
`id` bigint(30) NOT NULL AUTO_INCREMENT,
`title` varchar(255) DEFAULT NULL COMMENT '标题',
`description` longtext COMMENT '描述',
`is_read_only` varchar(1) DEFAULT NULL COMMENT '是否只读 1 是 0 否',
`del_flag` varchar(255) DEFAULT NULL COMMENT '是否有效 0 否 1 是',
`is_load` varchar(1) DEFAULT NULL COMMENT '上下架 0 否 1 是',
`operate_time` datetime DEFAULT NULL COMMENT '操作时间',
`operate_user` varchar(255) DEFAULT NULL COMMENT '操作用户',
`begin_time` varchar(100) DEFAULT NULL COMMENT '开始时间',
`end_time` varchar(100) DEFAULT NULL COMMENT '结束时间',
`link_url` varchar(255) DEFAULT NULL COMMENT '问卷地址',
`link_key` varchar(255) DEFAULT NULL COMMENT '问卷key',
PRIMARY KEY (`id`) USING BTREE,
KEY `INDEX_LINK_KEY` (`link_key`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='问卷信息表';问卷题目表
DROP TABLE IF EXISTS `t_survey_question`;
CREATE TABLE `t_survey_question` (
`id` bigint(30) NOT NULL AUTO_INCREMENT,
`question_title` varchar(255) DEFAULT NULL COMMENT '问题标题',
`question_type` varchar(255) DEFAULT NULL COMMENT '问题类别(单选 多选 问答)',
`question_content` longtext COMMENT '问题内容(单选 多选)',
`operate_time` datetime DEFAULT NULL COMMENT '操作时间',
`operate_user` varchar(255) DEFAULT NULL COMMENT '操作用户',
`del_flag` varchar(1) DEFAULT NULL COMMENT '是否有效 0 否 1 是',
`is_load` varchar(1) DEFAULT NULL COMMENT '上下架 0 否 1 是',
`is_required` varchar(1) DEFAULT NULL COMMENT '是否必填 0 否 1 是',
`survey_id` bigint(30) DEFAULT NULL COMMENT '问卷Id',
`order_sort` int(10) DEFAULT NULL COMMENT '排序字段',
`total_num` int(10) DEFAULT NULL COMMENT '数量',
PRIMARY KEY (`id`) USING BTREE,
KEY `INDEX_SURVEY_ID` (`survey_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=103 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='问卷问题表';问卷题目选项表
DROP TABLE IF EXISTS `t_survey_item`;
CREATE TABLE `t_survey_item` (
`id` bigint(30) NOT NULL AUTO_INCREMENT,
`question_id` bigint(30) DEFAULT NULL COMMENT '问题Id',
`survey_id` bigint(30) DEFAULT NULL COMMENT '问卷ID',
`total_num` int(20) DEFAULT NULL COMMENT '总数量',
`question_type` varchar(100) DEFAULT NULL COMMENT '问题类别',
`choice_content` varchar(100) DEFAULT NULL COMMENT '选择内容',
`percent_num` varchar(20) DEFAULT NULL COMMENT '百分比',
`choice_key` varchar(100) DEFAULT NULL COMMENT '内容key',
PRIMARY KEY (`id`) USING BTREE,
KEY `INDEX_QUESTION_ID` (`question_id`) USING BTREE,
KEY `INDEX_SURVEY_ID` (`survey_id`) USING BTREE,
KEY `INDEX_CHOICE_INDEX` (`choice_content`,`question_type`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=160 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='问卷题目选项表';问卷答案表
DROP TABLE IF EXISTS `t_survey_answer`;
CREATE TABLE `t_survey_answer` (
`id` bigint(30) NOT NULL AUTO_INCREMENT,
`question_id` bigint(30) DEFAULT NULL COMMENT '问题Id',
`survey_id` bigint(30) DEFAULT NULL COMMENT '问卷ID',
`choice_content` varchar(3000) DEFAULT NULL COMMENT '选择(填写内容)',
`user_id` varchar(30) DEFAULT NULL COMMENT '用户ID',
`user_name` varchar(255) DEFAULT NULL COMMENT '用户名称',
`operate_time` datetime DEFAULT NULL COMMENT '操作时间',
`question_type` varchar(255) DEFAULT NULL COMMENT '问题类别',
`phone` varchar(100) DEFAULT NULL COMMENT '手机号',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `INDEX_QUESTION_ID` (`question_id`,`survey_id`,`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=41 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='问卷答案表';2、关键逻辑点
获取问卷信息频繁,增加缓存
问卷重复提交,利用redis increment以及前端置灰色
每个选项数量+1 ,异步线程
3、代码展示
管理后台+接口,代码不上传,需自己实现!
-
Android完成一个简单的问卷调查
2019-03-22 00:03:07android:text="大学生智能手机调查问卷" android:textSize="20sp"> android:layout_width="match_parent" android:layout_height="1dip" android:layout_gravity="center_horizontal" android:layout_...MainActivity以及布局文件
MainActivity
package zzti.edu.cn.a0319; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.view.KeyEvent; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { private Button button; private RadioGroup radioGroupGender; private RadioGroup radioGroupTool; private RadioGroup radioGroupWhere; private RadioGroup radioGroupBrand; private List<CheckBox> list = new ArrayList<CheckBox>(); @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = findViewById(R.id.btn); radioGroupGender = findViewById(R.id.gender); radioGroupTool = findViewById(R.id.tool); radioGroupBrand = findViewById(R.id.brand); radioGroupWhere = findViewById(R.id.where); list.add((CheckBox) findViewById(R.id.checkbox1)); list.add((CheckBox) findViewById(R.id.checkbox2)); list.add((CheckBox) findViewById(R.id.checkbox3)); list.add((CheckBox) findViewById(R.id.checkbox4)); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int flag = 0; for (CheckBox checkBox : list) { if (checkBox.isChecked()) flag = 1; } if(flag==0){ Toast.makeText(MainActivity.this,"请完成问卷",Toast.LENGTH_LONG).show(); } else if((radioGroupBrand.getCheckedRadioButtonId()==-1||radioGroupGender.getCheckedRadioButtonId()==-1)||(radioGroupTool.getCheckedRadioButtonId()==-1||radioGroupWhere.getCheckedRadioButtonId()==-1)){ Toast.makeText(MainActivity.this,"请完成问卷",Toast.LENGTH_LONG).show(); }else{ Intent intent = new Intent(MainActivity.this, SubmitActivity.class); RadioButton radioButtonGender = findViewById(radioGroupGender.getCheckedRadioButtonId()); //System.out.println(radioButtonGender.getText()); intent.putExtra("gender", radioButtonGender.getText()); RadioButton radioButtonWhere = findViewById(radioGroupWhere.getCheckedRadioButtonId()); //System.out.println(radioButtonWhere.getText()); intent.putExtra("where", radioButtonWhere.getText()); RadioButton radioButtonTool = findViewById(radioGroupTool.getCheckedRadioButtonId()); // System.out.println(radioButtonTool.getText()); intent.putExtra("tool", radioButtonTool.getText()); RadioButton radioButtonBrand = findViewById(radioGroupBrand.getCheckedRadioButtonId()); //System.out.println(radioButtonBrand.getText()); intent.putExtra("brand", radioButtonBrand.getText()); String s = ""; for (CheckBox checkBox : list) { if (checkBox.isChecked()) s = s + checkBox.getText() + " "; } //System.out.println(s); intent.putExtra("useAge", s); startActivity(intent); } } }); } }
activity_main
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:orientation="horizontal" android:paddingLeft="10dp"> <ImageView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:src="@drawable/header" /> <TextView android:layout_width="0dp" android:layout_height="50dp" android:layout_weight="8" android:gravity="center" android:text="大学生智能手机调查问卷" android:textSize="20sp"></TextView> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="1dip" android:layout_gravity="center_horizontal" android:layout_marginTop="8dp" android:background="#000000" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="18dp" android:orientation="vertical" android:paddingLeft="18dp"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Q1:你的性别?*(必填)(单选)" android:textSize="18dp" /> <RadioGroup android:id="@+id/gender" android:layout_width="match_parent" android:layout_height="wrap_content"> <RadioButton android:id="@+id/s1" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="10dp" android:text="男"></RadioButton> <RadioButton android:id="@+id/s2" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="10dp" android:text="女" /> </RadioGroup> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:orientation="vertical" android:paddingLeft="18dp"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Q2:你平时上网所使用的主要工具?*(必填)(单选)" android:textSize="18dp" /> <RadioGroup android:id="@+id/tool" android:layout_width="match_parent" android:layout_height="wrap_content"> <RadioButton android:id="@+id/s3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" 平板电脑" /> <RadioButton android:id="@+id/s4" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" 智能手机" /> <RadioButton android:id="@+id/s5" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" 台式电脑" /> </RadioGroup> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:orientation="vertical" android:paddingLeft="18dp"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Q3:你使用智能手机的主要用途是?*(必填)(多选)" android:textSize="18dp" /> <CheckBox android:id="@+id/checkbox1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" 网页浏览" /> <CheckBox android:id="@+id/checkbox2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" 聊天" /> <CheckBox android:id="@+id/checkbox3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" 玩游戏" /> <CheckBox android:id="@+id/checkbox4" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" 电话短信" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingLeft="18dp"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Q4:你最想买的手机品牌是哪个?" android:textSize="18dp" /> <RadioGroup android:id="@+id/brand" android:layout_width="match_parent" android:layout_height="wrap_content"> <RadioButton android:id="@+id/s6" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" 苹果" /> <RadioButton android:id="@+id/s7" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" 三星" /> <RadioButton android:id="@+id/s8" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" 华为" /> <RadioButton android:id="@+id/s9" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" 小米"> </RadioButton> </RadioGroup> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingLeft="18dp"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Q5:你最近一款手机在哪里买的?" android:textSize="18dp" /> <RadioGroup android:id="@+id/where" android:layout_width="match_parent" android:layout_height="wrap_content"> <RadioButton android:id="@+id/s10" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" 大型商场" /> <RadioButton android:id="@+id/s11" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" 专卖店(三星,苹果店)" /> <RadioButton android:id="@+id/s12" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" 合约店购买" /> <RadioButton android:id="@+id/s13" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" 网上购买" /> <RadioButton android:id="@+id/s14" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=" 其他地方" /> </RadioGroup> </LinearLayout> <Button android:id="@+id/btn" android:layout_margin="20dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="提交" android:gravity="center" android:textColor="#000000" android:background="#3333CC" /> </LinearLayout> </ScrollView>
SubmitActivity以及布局文件
SubmitActivity
package zzti.edu.cn.a0319; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class SubmitActivity extends AppCompatActivity { private TextView textView1; private TextView textView2; private TextView textView3; private TextView textView4; private TextView textView5; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { Intent intent = this.getIntent(); String gender = intent.getStringExtra("gender"); String where = intent.getStringExtra("where"); String tool = intent.getStringExtra("tool"); String brand = intent.getStringExtra("brand"); String useAge = intent.getStringExtra("useAge"); super.onCreate(savedInstanceState); setContentView(R.layout.activity_submit); textView1 = findViewById(R.id.gender); textView1.setText("性别:"+gender); textView2 = findViewById(R.id.tool); textView2.setText("常使用的上网工具:"+tool); textView3 = findViewById(R.id.useAge); textView3.setText("使用智能手机的主要用途:"+useAge); textView4 = findViewById(R.id.brand); textView4.setText("最想拥有的手机品牌:"+brand); textView5 = findViewById(R.id.where); textView5.setText("最近一部手机在那里购买:"+where); button = findViewById(R.id.again_btn); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent1 = new Intent(SubmitActivity.this,MainActivity.class); startActivity(intent1); } }); } }
activity_submit
<?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"> <ImageView android:layout_width="match_parent" android:layout_height="200dp" android:src="@drawable/submit"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="感谢你的参与:结果如下:" android:gravity="center" android:textSize="18sp"/> <TextView android:id="@+id/gender" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="15sp" android:gravity="center"/> <TextView android:id="@+id/tool" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="15sp" android:gravity="center"/> <TextView android:id="@+id/useAge" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="15sp" android:gravity="center"/> <TextView android:id="@+id/brand" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="15sp" android:gravity="center"/> <TextView android:id="@+id/where" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="15sp" android:gravity="center"/> <Button android:layout_margin="10dp" android:id="@+id/again_btn" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#99668F" android:text="重新填写"/> </LinearLayout>
-
Android:设计一个简单的调查问卷
2018-11-04 11:57:35设计一个简单的调查问卷,要求用到TextView,Button,CheckBox,RadioButton,EditText等控件 今天写了一个demo,里面用到了常用的布局,以及常用的几种控件,这里调查问卷名字为大学生日常消费调查问卷,是参考网上的...设计一个简单的调查问卷,要求用到TextView,Button,CheckBox,RadioButton,EditText等控件
今天写了一个demo,里面用到了常用的布局,以及常用的几种控件,这里调查问卷名字为大学生日常消费调查问卷,是参考网上的常用调查问卷,选择了几个问题,为了省事,这里我只选择了6个问题,最终效果:用户填写完调查问卷,点击提交,页面跳转到另一个结果页面,显示用户提交的数据结果,当点击提交时如果有未填项,则不能跳转。主要为了练习常用布局以及控件的使用。
最终效果图
设计要点:
- 使用ScrollView 来实现屏幕的滚动效果;
- RadioGroup与RadioButton的配合使用;
- RadioGroup与CheckBox事件监听的实现;
- 显示页面QuestionnaireActivity与结果页面QuestionnaireResultActivity之间数据的传递;
其中问卷显示页面代码如下
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#EEEEEE" tools:context="com.fang.zzti.layout.Questionnaire"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="50dp" android:gravity="center" android:background="#0099FF" android:text="大学生日常消费调查问卷" android:textSize="25dp" android:textColor="@color/white" /> <!--性别--> <TextView android:layout_width="wrap_content" android:layout_height="match_parent" android:text="1.您的性别是:" android:textSize="25dp" android:layout_marginTop="30dp" android:layout_marginLeft="10dp" /> <RadioGroup android:id="@+id/rg_gender" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="10dp" android:background="@color/white" > <RadioButton android:id="@+id/rb_man" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="男" android:textSize="25dp" /> <RadioButton android:id="@+id/rb_woman" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:text="女" android:textSize="25dp" /> </RadioGroup> <!--2.院系--> <TextView android:layout_width="wrap_content" android:layout_height="match_parent" android:text="2.您的院系是:" android:textSize="25dp" android:layout_marginTop="30dp" android:layout_marginLeft="10dp" /> <RadioGroup android:id="@+id/rg_department" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@color/white" android:layout_marginLeft="10dp" android:layout_marginRight="10dp"> <RadioButton android:id="@+id/rb_department1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="软件学院" android:textSize="25dp" android:paddingTop="5dp" /> <RadioButton android:id="@+id/rb_department2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="计算机学院" android:textSize="25dp" android:paddingTop="5dp" /> <RadioButton android:id="@+id/rb_department3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="外语学院" android:textSize="25dp" android:paddingTop="5dp" /> <RadioButton android:id="@+id/rb_department4" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="其他学院" android:textSize="25dp" android:paddingTop="5dp" /> </RadioGroup> <!--3.年级--> <TextView android:layout_width="wrap_content" android:layout_height="match_parent" android:text="3.您的年级是:" android:textSize="25dp" android:layout_marginTop="30dp" android:layout_marginLeft="10dp" /> <RadioGroup android:id="@+id/rg_grade" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@color/white" android:layout_marginLeft="10dp" android:layout_marginRight="10dp"> <RadioButton android:id="@+id/rb_grade1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="大一" android:textSize="25dp" android:paddingTop="5dp" /> <RadioButton android:id="@+id/rb_grade2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="大二" android:textSize="25dp" android:paddingTop="5dp" /> <RadioButton android:id="@+id/rb_grade3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="大三" android:textSize="25dp" android:paddingTop="5dp" /> <RadioButton android:id="@+id/rb_grade4" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="大四" android:textSize="25dp" android:paddingTop="5dp" /> </RadioGroup> <!--4.每月消费--> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="4.您的在校期间平均月消费为:" android:textSize="25dp" android:layout_marginTop="30dp" android:layout_marginLeft="10dp" /> <RadioGroup android:id="@+id/rg_consume" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@color/white" android:layout_marginLeft="10dp" android:layout_marginRight="10dp"> <RadioButton android:id="@+id/rb_consume1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="600以下" android:textSize="25dp" android:paddingTop="5dp" /> <RadioButton android:id="@+id/rb_consume2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="600-1000" android:textSize="25dp" android:paddingTop="5dp" /> <RadioButton android:id="@+id/rb_consume3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="1000-1500" android:textSize="25dp" android:paddingTop="5dp" /> <RadioButton android:id="@+id/rb_consume4" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="1500元以上" android:textSize="25dp" android:paddingTop="5dp" /> </RadioGroup> <!--5.主要消费用途--> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="5.您每月消费主要在哪些方面:" android:textSize="25dp" android:layout_marginTop="30dp" android:layout_marginLeft="10dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@color/white" android:layout_marginLeft="10dp" android:layout_marginRight="10dp"> <CheckBox android:id="@+id/cb_mainconsume_a" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="25dp" android:text="A.伙食"/> <CheckBox android:id="@+id/cb_mainconsume_b" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="25dp" android:text="B.购物(服装、饰品)"/> <CheckBox android:id="@+id/cb_mainconsume_c" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="25dp" android:text="C.学习费用(书籍)"/> <CheckBox android:id="@+id/cb_mainconsume_d" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="25dp" android:text="D.娱乐"/> <CheckBox android:id="@+id/cb_mainconsume_e" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="25dp" android:text="E.上网消费"/> <CheckBox android:id="@+id/cb_mainconsume_f" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="25dp" android:text="F.恋爱"/> <CheckBox android:id="@+id/cb_mainconsume_g" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="25dp" android:text="G.其他"/> </LinearLayout> <!--6.建议--> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="6.请对大学生消费情况提出您宝贵的建议:" android:textSize="25dp" android:layout_marginTop="30dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp"/> <EditText android:id="@+id/et_suggest" android:layout_width="match_parent" android:layout_height="100dp" android:background="@color/white" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:inputType="text"/> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:layout_marginTop="20dp" android:layout_marginBottom="20dp" > <Button android:id="@+id/btn_submit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="提交" android:textColor="@color/white" android:background="@color/submit"/> <Button android:id="@+id/btn_exit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/btn_submit" android:layout_marginLeft="10dp" android:textColor="@color/white" android:background="@color/submit" android:text="退出"/> </RelativeLayout> </LinearLayout> </ScrollView>
设置监听器
其中单选按钮RadioButton一般是由RadioGroup响应,所以这里实现RadioGroup.OnCheckedChangeListener,而复选框CheckBox监听要实现CompoundButton.OnCheckedChangeListener,另外Button点击事件的监听要实现View.OnClickListener,代码如下:
public class Questionnaire extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener, CompoundButton.OnCheckedChangeListener, View.OnClickListener{
显示页面核心代码:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_questionnaire); initView(); } public void initView(){ // 性别 rg_gender=(RadioGroup)findViewById(R.id.rg_gender); rb_gender1=(RadioButton)findViewById(R.id.rb_man); rb_gender2=(RadioButton)findViewById(R.id.rb_woman); // 学院 rg_department=(RadioGroup)findViewById(R.id.rg_department); rb_department1=(RadioButton)findViewById(R.id.rb_department1); rb_department2=(RadioButton)findViewById(R.id.rb_department2); rb_department3=(RadioButton)findViewById(R.id.rb_department3); rb_department4=(RadioButton)findViewById(R.id.rb_department4); //消费 rg_consume=(RadioGroup)findViewById(R.id.rg_consume); rb_consume1=(RadioButton)findViewById(R.id.rb_consume1); rb_consume2=(RadioButton)findViewById(R.id.rb_consume2); rb_consume3=(RadioButton)findViewById(R.id.rb_consume3); rb_consume4=(RadioButton)findViewById(R.id.rb_consume4); //年级 rg_grade=(RadioGroup)findViewById(R.id.rg_grade); rb_grade1=(RadioButton)findViewById(R.id.rb_grade1); rb_grade2=(RadioButton)findViewById(R.id.rb_grade2); rb_grade3=(RadioButton)findViewById(R.id.rb_grade3); rb_grade4=(RadioButton)findViewById(R.id.rb_grade4); // 主要消费 cb_meal=(CheckBox)findViewById(R.id.cb_mainconsume_a); cb_shopping=(CheckBox)findViewById(R.id.cb_mainconsume_b); cb_study=(CheckBox)findViewById(R.id.cb_mainconsume_c); cb_amusement=(CheckBox)findViewById(R.id.cb_mainconsume_d); cb_internet=(CheckBox)findViewById(R.id.cb_mainconsume_e); cb_loveconsume=(CheckBox)findViewById(R.id.cb_mainconsume_f); cb_otherconsume=(CheckBox)findViewById(R.id.cb_mainconsume_g); // 建议 et_suggest=(EditText)findViewById(R.id.et_suggest); bt_submit=(Button)findViewById(R.id.btn_submit); bt_exit=findViewById(R.id.btn_exit); bt_submit.setOnClickListener(this); bt_exit.setOnClickListener(this); rg_gender.setOnCheckedChangeListener(this); rg_department.setOnCheckedChangeListener(this); rg_consume.setOnCheckedChangeListener(this); rg_grade.setOnCheckedChangeListener(this); cb_shopping.setOnCheckedChangeListener(this); cb_meal.setOnCheckedChangeListener(this); cb_otherconsume.setOnCheckedChangeListener(this); cb_study.setOnCheckedChangeListener(this); cb_amusement.setOnCheckedChangeListener(this); cb_loveconsume.setOnCheckedChangeListener(this); cb_internet.setOnCheckedChangeListener(this); mainConsume=new ArrayList<String>(); } @Override public void onCheckedChanged(RadioGroup radioGroup, int checkedId) { switch (checkedId){ case R.id.rb_man: gender=rb_gender1.getText().toString(); //Toast.makeText(this,"你选择了"+rb_gender1.getText().toString(),Toast.LENGTH_LONG).show(); break; case R.id.rb_woman: gender=rb_gender2.getText().toString(); // Toast.makeText(this,"你选择了"+rb_gender2.getText().toString(),Toast.LENGTH_LONG).show(); break; case R.id.rb_department1: department=rb_department1.getText().toString(); // Toast.makeText(this,"你选择了"+rb_department1.getText().toString(),Toast.LENGTH_LONG).show(); break; case R.id.rb_department2: department=rb_department2.getText().toString(); //Toast.makeText(this,"你选择了"+rb_department2.getText().toString(),Toast.LENGTH_LONG).show(); break; case R.id.rb_department3: department=rb_department3.getText().toString(); //Toast.makeText(this,"你选择了"+rb_department3.getText().toString(),Toast.LENGTH_LONG).show(); break; case R.id.rb_department4: department=rb_department4.getText().toString(); //Toast.makeText(this,"你选择了"+rb_department4.getText().toString(),Toast.LENGTH_LONG).show(); break; case R.id.rb_consume1: consume=rb_consume1.getText().toString(); //Toast.makeText(this,"你选择了"+rb_consume1.getText().toString(),Toast.LENGTH_LONG).show(); break; case R.id.rb_consume2: consume=rb_consume2.getText().toString(); //Toast.makeText(this,"你选择了"+rb_consume2.getText().toString(),Toast.LENGTH_LONG).show(); break; case R.id.rb_consume3: consume=rb_consume3.getText().toString(); //Toast.makeText(this,"你选择了"+rb_consume3.getText().toString(),Toast.LENGTH_LONG).show(); break; case R.id.rb_consume4: consume=rb_consume4.getText().toString(); // Toast.makeText(this,"你选择了"+rb_consume4.getText().toString(),Toast.LENGTH_LONG).show(); break; case R.id.rb_grade1: grade=rb_grade1.getText().toString(); // Toast.makeText(this,"你选择了"+rb_grade1.getText().toString(),Toast.LENGTH_LONG).show(); break; case R.id.rb_grade2: grade=rb_grade2.getText().toString(); //Toast.makeText(this,"你选择了"+rb_grade2.getText().toString(),Toast.LENGTH_LONG).show(); break; case R.id.rb_grade3: grade=rb_grade3.getText().toString(); // Toast.makeText(this,"你选择了"+rb_grade3.getText().toString(),Toast.LENGTH_LONG).show(); break; case R.id.rb_grade4: grade=rb_grade4.getText().toString(); //Toast.makeText(this,"你选择了"+rb_grade4.getText().toString(),Toast.LENGTH_LONG).show(); break; } } @Override public void onCheckedChanged(CompoundButton checkbox, boolean isChecked) { // checkbox.setChecked(!isChecked); int checkboxId=checkbox.getId(); //Toast.makeText(this,"checkboxId:"+checkboxId,Toast.LENGTH_LONG).show(); switch (checkboxId){ case R.id.cb_mainconsume_a: mainConsume.add(cb_meal.getText().toString()); // Toast.makeText(this,"你选择了"+cb_meal.getText().toString()+"check:"+isChecked,Toast.LENGTH_LONG).show(); break; case R.id.cb_mainconsume_b: mainConsume.add(cb_shopping.getText().toString()); // Toast.makeText(this,"你选择了"+cb_shopping.getText().toString()+"check:"+isChecked,Toast.LENGTH_LONG).show(); break; case R.id.cb_mainconsume_c: mainConsume.add(cb_study.getText().toString()); // Toast.makeText(this,"你选择了"+cb_shopping.getText().toString()+"check:"+isChecked,Toast.LENGTH_LONG).show(); break; case R.id.cb_mainconsume_d: mainConsume.add(cb_amusement.getText().toString()); // Toast.makeText(this,"你选择了"+cb_shopping.getText().toString()+"check:"+isChecked,Toast.LENGTH_LONG).show(); break; case R.id.cb_mainconsume_e: mainConsume.add(cb_internet.getText().toString()); //Toast.makeText(this,"你选择了"+cb_shopping.getText().toString()+"check:"+isChecked,Toast.LENGTH_LONG).show(); break; case R.id.cb_mainconsume_f: mainConsume.add(cb_loveconsume.getText().toString()); // Toast.makeText(this,"你选择了"+cb_shopping.getText().toString()+"check:"+isChecked,Toast.LENGTH_LONG).show(); break; case R.id.cb_mainconsume_g: mainConsume.add(cb_otherconsume.getText().toString()); // Toast.makeText(this,"你选择了"+cb_shopping.getText().toString()+"check:"+isChecked,Toast.LENGTH_LONG).show(); break; } } @Override public void onClick(View view) { if(view.getId()==R.id.btn_submit){ suggestion= String.valueOf(et_suggest.getText().toString().trim()); if(gender==null||department==null||grade==null||consume==null||mainConsume.size()==0){ Toast.makeText(this, "您有未填写的项目!", Toast.LENGTH_SHORT).show(); }else{ if(TextUtils.isEmpty(et_suggest.getText())){ Toast.makeText(this, "请填写您的建议", Toast.LENGTH_SHORT).show(); }else{ //进行页面的跳转和数据的传递 Intent intent=new Intent(this,QuestionnaireResult.class); Bundle bundle=new Bundle(); bundle.putString("gender",gender); bundle.putString("department",department); bundle.putString("grade",grade); bundle.putString("consume",consume); bundle.putStringArrayList("mainConsume", (ArrayList<String>) mainConsume); bundle.putString("suggestion",suggestion); intent.putExtras(bundle); startActivity(intent); } } }else if(view.getId()==R.id.btn_exit){ this.finish(); } }
QuestionnaireResult结果页面xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.fang.zzti.layout.QuestionnaireResult"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="50dp" android:text="您的问卷结果如下:" android:textSize="30dp" android:gravity="center" /> <TextView android:id="@+id/tv_gender" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30dp"/> <TextView android:id="@+id/tv_department" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30dp"/> <TextView android:id="@+id/tv_grade" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30dp"/> <TextView android:id="@+id/tv_consume" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30dp"/> <TextView android:id="@+id/tv_mainConsume" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30dp"/> <TextView android:id="@+id/tv_suggestion" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30dp"/> </LinearLayout> </LinearLayout>
结果页面
public class QuestionnaireResult extends AppCompatActivity { private TextView tv_gender; private TextView tv_department; private TextView tv_grade; private TextView tv_consume; private TextView tv_mainConsume; private TextView tv_suggestion; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_questionnaire_result); initView(); } private void initView() { tv_gender=(TextView)findViewById(R.id.tv_gender); tv_department=(TextView)findViewById(R.id.tv_department); tv_grade=(TextView)findViewById(R.id.tv_grade); tv_consume=findViewById(R.id.tv_consume); tv_mainConsume=findViewById(R.id.tv_mainConsume); tv_suggestion=findViewById(R.id.tv_suggestion); Intent intent=getIntent(); Bundle bundle=intent.getExtras(); String gender=bundle.getString("gender",""); String department=bundle.getString("department",""); String grade=bundle.getString("grade",""); String consume=bundle.getString("consume",""); ArrayList<String> mainConsume=bundle.getStringArrayList("mainConsume"); String suggestion=bundle.getString("suggestion"); String mainConsumeStr=""; tv_gender.setText("性别:"+gender); tv_department.setText("学院:"+department); tv_grade.setText("年级:"+grade); tv_consume.setText("月消费情况:"+consume); for(int i=0;i<mainConsume.size();i++){ mainConsumeStr+="\t\t"+mainConsume.get(i)+"\n"; } tv_mainConsume.setText("您的主要消费项目为:\n"+mainConsumeStr); tv_suggestion.setText("您的建议为:\n"+suggestion); } }
问卷显示结果页面效果图
其中遇到的问题
ArrayList忘记初始化,总是获取不到复选框的值,每次程序运行,一点击复选框,程序自动崩溃,且出错时系统没有错误提示信息,坑!
源码下载:https://download.csdn.net/download/zhangyifang_009/12490374
-
做一个简单的问卷调查功能,flex和flash哪个适合?
2011-01-17 19:03:07做一个简单的问卷调查功能,flex和flash哪个适合,请熟悉的朋友 从性能、难易度、文件大小,集成难度方面上给一下指导意见. -
jsp一个简单的调查问卷
2016-09-08 17:14:02明天数模比赛了,队友看的出来还是比较紧张的,然而程序员表示反正就是看牛皮怎么吹23333,今天完善了一个最简单的问卷系统。 遇到的问题有一下几点: 1,连接mysql的jar包一定要先放在WEB-INF下的lib文件夹下,然后再... -
使用 Vue.js 制作一个简单的调查问卷平台
2017-01-08 23:54:45使用 Vue.js 制作一个简单的调查问卷平台 原文 https://github.com/pramper/Demos/tree/master/Vue-Demos/Questionnaire 主题 Vue.js Questionnaire 一个用Vue.js写的微型问卷调查 任务基于... -
php实现简单的问卷调查系统,可自定制试题
2020-07-20 07:32:28php写一个简单问卷调查系统,简单的实现自定义试卷题目,用户管理,普通用户和超级用户登录进入不同的界面,进行不同的操作 -
Android开发:实现简单的问卷调查
2019-06-16 18:15:24Android开发:实现简单的问卷调查 1.activity_main.xml 主界面整体是由ScrollView控件控制,ScrollView它继承自FrameLayout,所以它是一种特殊类型的FrameLayout,因为它可以使用用户滚动显示一个占据的空间大于... -
用access开发的简单问卷调查
2018-04-11 14:15:14一个表,一个窗体。最简单的开发。统计问卷数据时可以参考开发。 -
php实现的简单问卷调查系统
2017-04-30 23:10:28php实现的简单问卷调查系统最近尝试用php写一个简单问卷调查系统,简单的实现自定义试卷题目,用户管理,普通用户和超级用户登录进入不同的界面,进行不同的操作。 废话不多说,直接看效果图吧: 下图是普通用户...