├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── assets
│ │ │ └── question.db
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── lgl
│ │ │ │ └── answersystem
│ │ │ │ ├── Question.java
│ │ │ │ ├── DBService.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── lgl
│ │ │ └── answersystem
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── lgl
│ │ └── answersystem
│ │ └── ApplicationTest.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | AnswerSystem
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/src/main/assets/question.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xfzyy/AnswerSystem/HEAD/app/src/main/assets/question.db
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 答题系统
3 |
4 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xfzyy/AnswerSystem/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xfzyy/AnswerSystem/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xfzyy/AnswerSystem/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xfzyy/AnswerSystem/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xfzyy/AnswerSystem/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xfzyy/AnswerSystem/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/test/java/com/lgl/answersystem/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.lgl.answersystem;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/lgl/answersystem/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.lgl.answersystem;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AnswerSystem
2 |
3 | >Android-自己设计数据库的答题系统
4 |
5 | >博客地址:http://blog.csdn.net/qq_26787115/article/details/51586096
6 |
7 |
8 |
9 | 
10 |
11 |
12 | ####QQ邮箱:748778890@qq.com
13 | ####Google邮箱:liuguilin74@gmail.com
14 | ####博客地址:http://blog.csdn.net/qq_26787115
15 |
16 | ---
17 | ###我的公众号,期待你的关注
18 | 
19 | ###[点击关注我的微博](http://weibo.com/Glorystys)
20 |
21 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lgl/answersystem/Question.java:
--------------------------------------------------------------------------------
1 | package com.lgl.answersystem;
2 |
3 | /**
4 | * 保存数据库数据
5 | * Created by LGL on 2016/6/4.
6 | */
7 | public class Question {
8 |
9 | /**
10 | * 对应的就是Filter1-7 还有一个选中答案
11 | */
12 |
13 | //编号
14 | public int ID;
15 | //问题
16 | public String question;
17 | //四个选项
18 | public String answerA;
19 | public String answerB;
20 | public String answerC;
21 | public String answerD;
22 | //答案
23 | public int answer;
24 | //详情
25 | public String explaination;
26 |
27 | //用户选中的答案
28 | public int selectedAnswer;
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.lgl.answersystem"
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.3.0'
26 | }
27 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\AndroidDelepoer\androidSdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Sat Jun 04 19:12:24 CST 2016
16 | systemProp.http.proxyHost=mirrors.opencas.cn
17 | systemProp.http.proxyPort=80
18 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lgl/answersystem/DBService.java:
--------------------------------------------------------------------------------
1 | package com.lgl.answersystem;
2 |
3 | import android.database.Cursor;
4 | import android.database.sqlite.SQLiteDatabase;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | /**
10 | * 连接数据库
11 | * Created by LGL on 2016/6/4.
12 | */
13 | public class DBService {
14 |
15 | private SQLiteDatabase db;
16 |
17 | //构造方法
18 | public DBService() {
19 | //连接数据库
20 | db = SQLiteDatabase.openDatabase("/data/data/com.lgl.answersystem/databases/question.db", null, SQLiteDatabase.OPEN_READWRITE);
21 |
22 | }
23 |
24 | //获取数据库的数据
25 | public List getQuestion() {
26 | List list = new ArrayList<>();
27 | //执行sql语句
28 | Cursor cursor = db.rawQuery("select * from question", null);
29 | if (cursor.getCount() > 0) {
30 | cursor.moveToFirst();
31 | int count = cursor.getCount();
32 | //遍历
33 | for (int i = 0; i < count; i++) {
34 | cursor.moveToPosition(i);
35 | Question question = new Question();
36 | //ID
37 | question.ID = cursor.getInt(cursor.getColumnIndex("Field1"));
38 | //问题
39 | question.question = cursor.getString(cursor.getColumnIndex("Field2"));
40 | //四个选择
41 | question.answerA = cursor.getString(cursor.getColumnIndex("Field3"));
42 | question.answerB = cursor.getString(cursor.getColumnIndex("Field4"));
43 | question.answerC = cursor.getString(cursor.getColumnIndex("Field5"));
44 | question.answerD = cursor.getString(cursor.getColumnIndex("Field6"));
45 | //答案
46 | question.answer = cursor.getInt(cursor.getColumnIndex("Field7"));
47 | //解析
48 | question.explaination = cursor.getString(cursor.getColumnIndex("Field8"));
49 | //设置为没有选择任何选项
50 | question.selectedAnswer = -1;
51 | list.add(question);
52 | }
53 | }
54 | return list;
55 |
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
13 |
14 |
19 |
20 |
28 |
29 |
34 |
35 |
36 |
37 |
38 |
43 |
44 |
49 |
50 |
55 |
56 |
61 |
62 |
63 |
64 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
87 |
88 |
89 |
95 |
96 |
102 |
103 |
104 |
105 |
106 |
107 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/lgl/answersystem/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.lgl.answersystem;
2 |
3 | import android.content.DialogInterface;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AlertDialog;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.widget.Button;
9 | import android.widget.RadioButton;
10 | import android.widget.RadioGroup;
11 | import android.widget.TextView;
12 |
13 | import java.io.File;
14 | import java.io.FileOutputStream;
15 | import java.io.IOException;
16 | import java.io.InputStream;
17 | import java.io.OutputStream;
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | /**
22 | * 答题系统
23 | *
24 | * @author LGL
25 | */
26 | public class MainActivity extends AppCompatActivity {
27 |
28 | //数据库的名称
29 | private String DB_NAME = "question.db";
30 | //数据库的地址
31 | private String DB_PATH = "/data/data/com.lgl.answersystem/databases/";
32 | //总的题目数据
33 | private int count;
34 | //当前显示的题目
35 | private int corrent;
36 | //问题
37 | private TextView tv_title;
38 | //选项
39 | RadioButton[] mRadioButton = new RadioButton[4];
40 | //上一题
41 | private Button btn_up;
42 | //下一题
43 | private Button btn_down;
44 | //详情
45 | private TextView tv_result;
46 | //容器
47 | private RadioGroup mRadioGroup;
48 | //是否进入错题模式
49 | private boolean wrongMode;
50 |
51 | @Override
52 | protected void onCreate(Bundle savedInstanceState) {
53 | super.onCreate(savedInstanceState);
54 | setContentView(R.layout.activity_main);
55 |
56 | initFile();
57 | initView();
58 | initDB();
59 |
60 | }
61 |
62 | /**
63 | * 初始化View
64 | */
65 | private void initView() {
66 |
67 | wrongMode = false;
68 |
69 | tv_title = (TextView) findViewById(R.id.tv_title);
70 |
71 | mRadioButton[0] = (RadioButton) findViewById(R.id.RadioA);
72 | mRadioButton[1] = (RadioButton) findViewById(R.id.RadioB);
73 | mRadioButton[2] = (RadioButton) findViewById(R.id.RadioC);
74 | mRadioButton[3] = (RadioButton) findViewById(R.id.RadioD);
75 |
76 | btn_down = (Button) findViewById(R.id.btn_down);
77 | btn_up = (Button) findViewById(R.id.btn_up);
78 |
79 | tv_result = (TextView) findViewById(R.id.tv_result);
80 |
81 | mRadioGroup = (RadioGroup) findViewById(R.id.mRadioGroup);
82 | }
83 |
84 | /**
85 | * 初始化数据库服务
86 | */
87 | private void initDB() {
88 | DBService dbService = new DBService();
89 | final List list = dbService.getQuestion();
90 |
91 | count = list.size();
92 | corrent = 0;
93 |
94 | Question q = list.get(0);
95 | tv_title.setText(q.question);
96 |
97 | mRadioButton[0].setText(q.answerA);
98 | mRadioButton[1].setText(q.answerB);
99 | mRadioButton[2].setText(q.answerC);
100 | mRadioButton[3].setText(q.answerD);
101 |
102 | //上一题
103 | btn_up.setOnClickListener(new View.OnClickListener() {
104 | @Override
105 | public void onClick(View v) {
106 | if (corrent > 0) {
107 | corrent--;
108 |
109 | Question q = list.get(corrent);
110 |
111 | tv_title.setText(q.question);
112 |
113 | mRadioButton[0].setText(q.answerA);
114 | mRadioButton[1].setText(q.answerB);
115 | mRadioButton[2].setText(q.answerC);
116 | mRadioButton[3].setText(q.answerD);
117 |
118 | tv_result.setText(q.explaination);
119 |
120 | mRadioGroup.clearCheck();
121 |
122 | //设置选中
123 | if (q.selectedAnswer != -1) {
124 | mRadioButton[q.selectedAnswer].setChecked(true);
125 | }
126 | }
127 |
128 | }
129 | });
130 |
131 | //下一题
132 | btn_down.setOnClickListener(new View.OnClickListener() {
133 | @Override
134 | public void onClick(View v) {
135 | //判断是否为最后一题
136 | if (corrent < count - 1) {
137 | corrent++;
138 | Question q = list.get(corrent);
139 |
140 | tv_title.setText(q.question);
141 |
142 | mRadioButton[0].setText(q.answerA);
143 | mRadioButton[1].setText(q.answerB);
144 | mRadioButton[2].setText(q.answerC);
145 | mRadioButton[3].setText(q.answerD);
146 |
147 | tv_result.setText(q.explaination);
148 |
149 | mRadioGroup.clearCheck();
150 |
151 | //设置选中
152 | if (q.selectedAnswer != -1) {
153 | mRadioButton[q.selectedAnswer].setChecked(true);
154 | }
155 | } else if (corrent == count - 1 && wrongMode == true) {
156 |
157 | new AlertDialog.Builder(MainActivity.this).setTitle("提示").setMessage("已经到达最后一道题,是否退出?")
158 | .setPositiveButton("确定", new DialogInterface.OnClickListener() {
159 | @Override
160 | public void onClick(DialogInterface dialog, int which) {
161 | finish();
162 | }
163 | }).setNegativeButton("取消",null).show();
164 |
165 | } else {
166 | //没有题目了,开始检测正确性
167 | final List wrongList = checkAnswer(list);
168 |
169 | if(wrongList.size() == 0){
170 | new AlertDialog.Builder(MainActivity.this).setTitle("提示").setMessage("你好厉害,答对了所有题!")
171 | .setPositiveButton("确定", new DialogInterface.OnClickListener() {
172 | @Override
173 | public void onClick(DialogInterface dialog, int which) {
174 | finish();
175 | }
176 | }).setNegativeButton("取消",null).show();
177 | }
178 |
179 | //窗口提示
180 | new AlertDialog.Builder(MainActivity.this).setTitle("恭喜,答题完成!")
181 | .setMessage("答对了" + (list.size() - wrongList.size()) + "道题" + "\n"
182 | + "答错了" + wrongList.size() + "道题" + "\n" + "是否查看错题?").setPositiveButton("确定", new DialogInterface.OnClickListener() {
183 | @Override
184 | public void onClick(DialogInterface dialog, int which) {
185 | wrongMode = true;
186 | List newList = new ArrayList();
187 | for (int i = 0; i < wrongList.size(); i++) {
188 | newList.add(list.get(wrongList.get(i)));
189 | }
190 | list.clear();
191 | for (int i = 0; i < newList.size(); i++) {
192 | list.add(newList.get(i));
193 | }
194 | corrent = 0;
195 | count = list.size();
196 |
197 | //更新当前显示的内容
198 | Question q = list.get(corrent);
199 |
200 | tv_title.setText(q.question);
201 |
202 | mRadioButton[0].setText(q.answerA);
203 | mRadioButton[1].setText(q.answerB);
204 | mRadioButton[2].setText(q.answerC);
205 | mRadioButton[3].setText(q.answerD);
206 |
207 | tv_result.setText(q.explaination);
208 | //显示结果
209 | tv_result.setVisibility(View.VISIBLE);
210 | }
211 | }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
212 | @Override
213 | public void onClick(DialogInterface dialog, int which) {
214 | finish();
215 | }
216 | }).show();
217 | }
218 | }
219 | });
220 |
221 | //答案选中
222 | mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
223 | @Override
224 | public void onCheckedChanged(RadioGroup group, int checkedId) {
225 | for (int i = 0; i < 4; i++) {
226 | if (mRadioButton[i].isChecked() == true) {
227 | list.get(corrent).selectedAnswer = i;
228 | break;
229 | }
230 | }
231 | }
232 | });
233 | }
234 |
235 | /**
236 | * 判断是否答题正确
237 | *
238 | * @param list
239 | * @return
240 | */
241 | private List checkAnswer(List list) {
242 | List wrongList = new ArrayList<>();
243 | for (int i = 0; i < list.size(); i++) {
244 | //判断对错
245 | if (list.get(i).answer != list.get(i).selectedAnswer){
246 | wrongList.add(i);
247 | }
248 | }
249 | return wrongList;
250 | }
251 |
252 | /**
253 | * 将数据库拷贝到相应目录
254 | */
255 | private void initFile() {
256 | //判断数据库是否拷贝到相应的目录下
257 | if (new File(DB_PATH + DB_NAME).exists() == false) {
258 | File dir = new File(DB_PATH);
259 | if (!dir.exists()) {
260 | dir.mkdir();
261 | }
262 |
263 | //复制文件
264 | try {
265 | InputStream is = getBaseContext().getAssets().open(DB_NAME);
266 | OutputStream os = new FileOutputStream(DB_PATH + DB_NAME);
267 |
268 | //用来复制文件
269 | byte[] buffer = new byte[1024];
270 | //保存已经复制的长度
271 | int length;
272 |
273 | //开始复制
274 | while ((length = is.read(buffer)) > 0) {
275 | os.write(buffer, 0, length);
276 | }
277 |
278 | //刷新
279 | os.flush();
280 | //关闭
281 | os.close();
282 | is.close();
283 |
284 | } catch (IOException e) {
285 | e.printStackTrace();
286 | }
287 |
288 | }
289 | }
290 | }
291 |
--------------------------------------------------------------------------------