A library that allows you to integrate questions utilizing checkboxes that allow for a great user experience. There is full customization of the question views, allowing for seamless integration of a question into your apps UI. There are multiple types of questions that help you make simple questionaries to quizzes with multiple choice and multiple answer questions.

Overview

CheckboxQuestions

CheckboxQuestions is a library that provides with different forms of asking questions. So far there are YesOrNoQuestions, MultipleChoiceQuestions, and MultipleAnswerQuestions. These questions utilize checkboxes to make an elegant looking UI that will fit seamlessly into your app.

Table of Contents

Images

XML demo

demo

(Second question number is Two instead of 2 as to showcase you can put anything you want as a number)

QuestionList demo

Screen.Recording.2021-04-22.at.8.28.30.AM.mov

(Above video gets questions from an API)

Implementation

The latest stable release is v1.4.0

For Gradle

In your project level build.gradle first add JitPack:

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

In your app level build.gradle add:

dependencies {
    implementation 'com.github.Cyber-cp:CheckboxQuestions:LATEST_RELEASE'
}

For Maven

First add JitPack to your build file:

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Then add the dependancy:

	<dependency>
	    <groupId>com.github.Cyber-cp</groupId>
	    <artifactId>CheckboxQuestions</artifactId>
	    <version>LATEST_RELEASE</version>
	</dependency>

QuestionsList

This is the easiest way to add questions. This works by adding questions to a layout defined in your layout xml file. Here is an example layout file:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="10dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <LinearLayout
            android:id="@+id/questionLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center|top"
            android:orientation="vertical">

            <Button
                android:id="@+id/getAnswers"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="logAnswers"
                android:text="Press me!" />
        </LinearLayout>

    </ScrollView>


</androidx.constraintlayout.widget.ConstraintLayout>

(The button is to get answers, the scrollview is in case there are too many questions and they go offscreen)

We mainly only care about the linear layout in the scrollview.

LinearLayout linearLayout = findViewById(R.id.questionLayout);

Settings Builder

Now we want to create our QuestionList, but first you have to give it some settings so the view is displayed to your likings.

QuestionListSettings questionListSettings = new QuestionListSettings.SettingsBuilder()
                                .setCheckboxLocation(Question.LEFT)
                                .setCheckBoxOrientation(Question.SPLIT_VERTICAL)
                                .setNumberEnabled(false)
                                .setOptionTextSize(20)
                                .setQuestionTextSize(24)
                                .setSpacing(15)
                                .create();

The setCheckboxLocation() allows you to choose whether the options for the question are to the left, center, or right of the screen. The setCheckBoxOrientation() allows you to choose whether the options for the question are stacked or sideways to eachother. The setNumberEnabled() allows you to choose whether the questions have a visible number. The setSpacing() allows you to choose how far apart the options are from eachother. The setQuestionTextSize() and setOptionTextSize() allows you to choose the text size for the question and th options respectively.

List of questions

Now we want to create our list of questions. There are 2 ways to do this. If you want simple yes or no questionaire, just create a String array full of questions.

String[] string = new String[]{"Is 9+2 = 11?", "Are you happy?", "Did you eat breakfast?"};

If you want to make questions with a correct answer, create an ArrayList of Questions.

ArrayList<Question> list = new ArrayList<>();

list.add(new Question("How are you?", Question.NO_ANSWER, Question.MULTIPLE_CHOICE_QUESTION, "Good", "Bad"));
list.add(new Question("What is 17 * 5", 3, Question.MULTIPLE_CHOICE_QUESTION, "12", "22", "85", "105", "117"));

(You can add as many questions as you like)

Creating the QuestionList

Next we want to create our Question List using the settings you created and the list/array you created.

QuestionList questionList = new QuestionList(list, questionListSettings, context);

Getting the questions and diplaying them

Now if you want to create the views, just call createQuestionViews().

questionList.createQuestionViews();

To add the views to your layout, you can use:

linearLayout.addView(questionList.getQuestionViews());

All methods

createQuestionViews()

Generates all the question views. They are stored in a LinearLayout.

getQuestionViews()

Returns a LinearLayout full of question views.

areAllQuestionsAnswered()

Returns a boolean that is true if all the questions are answered, and false if not all are answered.

getPercentageOfCorrectAnswers()

Returns a decimal value of how many answers are correct.

getSelectedAnswers()

Returns an Object ArrayList filled with the selected answers. You can loop through the arraylist using for(Object answer : answers) and you can try to cast each answer to a specific object, like (int) answer.

getQuestion(int index)

Returns a view that can either be a MultipleChoiceQuestion or YesOrNoQuestion. You can cast the view to a specific type of question and do any methods you want with it.

((MultipleChoiceQuestion) questionList.getQuestion(1)).setCheckedOption(0);

addOnAnswerChangedListener(int index, OnAnswerChangedListener onAnswerChangedListener)

A listener which allows you to run code whenever the answer changes, the index is the index of the question in the QuestionList.

YesOrNoQuestions

YesOrNoQuestions are a simple form of question which show a question with a number, and only allow a yes or no as an answer, while MultipleChoiceQuestions allow anything as an option. To use it in an XML layout just use the following code:

<com.aadyad.checkboxquestion.Views.YesOrNoQuestion
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        app:number_enabled="true"
        app:spacing_between_boxes="35"
        app:checkbox_location="center"
        app:checkbox_orientation="horizontal"
        app:question_number="1"
        app:question_title="Do you have a cold?"
	app:correct_answer="0"
        app:question_text_size="20"
        app:option_text_size="18" />

Number Enabled

The number_enabled attribute allows you to make the number visible or not.

Spacing Between Boxes

The spacing_between_boxes attribute allows you to choose the spacing between the checkboxes.

Checkbox Location

The checkbox_location attribute allows you to choose whether the checkboxes are to the left, center, or right of the screen. To specify where they are just use app:checkbox_location="left", app:checkbox_location="center", orapp:checkbox_location="right".

Checkbox Orientation

The checkbox_orientation attribute allows you to choose whether the checkboxes are stacked or if they are horizontal. To stack them use app:checkbox_orientation="split_vertical" to use the horizontally use app:checkbox_orientation="horizontal"

Question Number

The question_number attribute allows you to set the number of the question.

Question Title

The question_title attribute allows you to set the question text.

Correct Answer

The correct_answer attribute allows you to set the correct answer. Put 0 for no answer.

Question Text Size

The question_text_size attribute allows you to set the question text size.

Option Text Size

The option_text_size attribute allows you to set the option text size.

Methods

addOnAnswerChangedListener(OnAnswerChangedListener onAnswerChangedListener)

A listener which allows you to run code whenever the answer changes.

setCheckedOption(String option)

Allows you to choose which option is checked using the option text.

setCheckedOption(int option)

Allows you to choose which option is checked using the index of the option (Starts at 1, NOT 0).

setCheckboxOrientation(int orientation)

Sets the orientation of the checkboxes.

setQuestionTextSize(float questionTextSize)

Sets the textsize of the question.

setOptionTextSize(float optionTextSize)

Sets the textsize for the options.

getSelectedAnswer()

Returns an int of the selected answer.

setQuestion(String question)

Sets the question text.

setQuestionNumber(String number)

Sets the question number.

getQuestionTitleTextView()

Returns the TextView which holds the question text.

getQuestionNumberTextView()

Returns the TextView which holds the question number text.

getCorrectAnswer()

Returns an int which is the index of the correct answer (the index starts at 1, NOT 0). If it returns 1 that means the first checkbox is the correct answer

isAnswerCorrect()

Returns a boolean that is true if the selected answer matches the correct answer, and false if it doesn't.

setCorrectAnswer(int correctAnswer)

Sets the correct answer of the question.

MultipleChoiceQuestions

<com.aadyad.checkboxquestion.Views.MultipleChoiceQuestion
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:question_title="What is the slope-intercept equation of a line?"
	app:correct_answer="0"
        app:question_number="10"
        app:number_enabled="true"
        app:option_text_size="20"
        app:question_text_size="25"
        app:spacing_between_boxes="30"
        app:checkbox_orientation="full_vertical"
        app:option_1="x = ym + b"
        app:option_2="y = mx + b"
        app:option_3="y = mb * x"
        app:option_4="b = my / x"/>

Number Enabled

The number_enabled attribute allows you to make the number visible or not.

Spacing Between Boxes

The spacing_between_boxes attribute allows you to choose the spacing between the checkboxes.

Checkbox Location

The checkbox_location attribute allows you to choose whether the checkboxes are to the left, center, or right of the screen. To specify where they are just use app:checkbox_location="left", app:checkbox_location="center", orapp:checkbox_location="right".

Checkbox Orientation

The checkbox_orientation attribute allows you to choose whether the checkboxes are stacked or if they are horizontal. To stack them use app:checkbox_orientation="split_vertical" to use the horizontally use app:checkbox_orientation="horizontal"

Question Number

The question_number attribute allows you to set the number of the question.

Question Title

The question_title attribute allows you to set the question text.

Correct Answer

The correct_answer attribute allows you to set the correct answer. Put 0 for no answer.

Question Text Size

The question_text_size attribute allows you to set the question text size.

Option Text Size

The option_text_size attribute allows you to set the option text size.

Options

The option_1 attribute lets you set the text for option 1. The option_2 attribute lets you set the text for option 2. The option_3 attribute lets you set the text for option 3. The option_4 attribute lets you set the text for option 4.

Methods

setCheckedOption(String option)

Allows you to choose which option is checked using the option text.

setCheckedOption(int option)

Allows you to choose which option is checked using the index of the option (Starts at 1, NOT 0).

addOnAnswerChangedListener(OnAnswerChangedListener onAnswerChangedListener)

A listener which allows you to run code whenever the answer changes.

setCheckboxOrientation(int orientation)

Sets the orientation of the checkboxes.

setQuestionTextSize(float questionTextSize)

Sets the textsize of the question.

setOptionTextSize(float optionTextSize)

Sets the textsize for the options.

getSelectedAnswer()

Returns an int of the selected answer.

setQuestion(String question)

Sets the question text.

getOptions()

Returns a String array with all the options the question provides.

getCheckbox(int index)

Returns a Checkbox object at a certain index (the index starts at 0).

getQuestionTitleTextView()

Returns the TextView which holds the question text.

getQuestionNumberTextView()

Returns the TextView which holds the question number text.

getCorrectAnswer()

Returns an int which is the index of the correct answer (the index starts at 1, NOT 0). If it returns 1 that means the first checkbox is the correct answer

isAnswerCorrect()

Returns a boolean that is true if the selected answer matches the correct answer, and false if it doesn't.

setCorrectAnswer(int correctAnswer)

Sets the correct answer of the question.

setOptionText(int index, String text)

Sets the text of an option retrieved by an index. The option is retrieved by the index in the order they can be seen in.

MultipleAnswerQuestions

<com.aadyad.checkboxquestion.Views.MultipleAnswerQuestion
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:question_title="Which equations are equivalent to 90 + 30"
        app:question_number="10"
        app:number_enabled="true"
        app:option_text_size="20"
        app:question_text_size="25"
        app:spacing_between_boxes="30"
        app:checkbox_orientation="full_vertical"
        app:option_1="91 + 29"
        app:option_2="50 + 70"
        app:option_3="100 + 20"
        app:option_4="99 + 890980"/>

Number Enabled

The number_enabled attribute allows you to make the number visible or not.

Spacing Between Boxes

The spacing_between_boxes attribute allows you to choose the spacing between the checkboxes.

Checkbox Location

The checkbox_location attribute allows you to choose whether the checkboxes are to the left, center, or right of the screen. To specify where they are just use app:checkbox_location="left", app:checkbox_location="center", orapp:checkbox_location="right".

Checkbox Orientation

The checkbox_orientation attribute allows you to choose whether the checkboxes are stacked or if they are horizontal. To stack them use app:checkbox_orientation="split_vertical" to use the horizontally use app:checkbox_orientation="horizontal"

Question Number

The question_number attribute allows you to set the number of the question.

Question Title

The question_title attribute allows you to set the question text.

Question Text Size

The question_text_size attribute allows you to set the question text size.

Option Text Size

The option_text_size attribute allows you to set the option text size.

Options

The option_1 attribute lets you set the text for option 1. The option_2 attribute lets you set the text for option 2. The option_3 attribute lets you set the text for option 3. The option_4 attribute lets you set the text for option 4.

Methods

setCheckedOption(String option)

Allows you to choose which option is checked using the option text.

setCheckedOption(int option)

Allows you to choose which option is checked using the index of the option (Starts at 1, NOT 0).

addOnAnswerChangedListener(OnAnswerChangedListener onAnswerChangedListener)

A listener which allows you to run code whenever the answer changes.

setCheckboxOrientation(int orientation)

Sets the orientation of the checkboxes.

setQuestionTextSize(float questionTextSize)

Sets the textsize of the question.

setOptionTextSize(float optionTextSize)

Sets the textsize for the options.

getSelectedAnswers()

Returns an Integer ArrayList of the selected answer.

setQuestion(String question)

Sets the question text.

getOptions()

Returns a String array with all the options the question provides.

getCheckbox(int index)

Returns a Checkbox object at a certain index (the index starts at 0).

getQuestionTitleTextView()

Returns the TextView which holds the question text.

getQuestionNumberTextView()

Returns the TextView which holds the question number text.

getCorrectAnswer()

Returns an Integer ArrayList which contains the indexes of the correct answers (the index starts at 1, NOT 0).

isAnswerCorrect()

Returns a boolean that is true if the selected answers matches the correct answer, and false if it doesn't.

setCorrectAnswer(ArrayList<Integer> correctAnswer)

Sets the correct answer of the question.

setOptionText(int index, String text)

Sets the text of an option retrieved by an index. The option is retrieved by the index in the order they can be seen in.

Questions

Questions are an object that allow you to make a QuestionList full of Multiple Choice Questions. There are 3 constructors for the Question object, which means there are 2 ways to define your Question object

One way:

Question q = new Question("What is the slope intercept equation of a line?", 2, Question.MULTIPLE_CHOICE_QUESTION, "x = yb + m", "y = mx + b", "m = yx + b", "b = mx + y");

The first argument that was passed is the question, The third arg is the type of question, the fourth arg is a String array full of possible answers, and the second arg is the index (this index STARTS at 1, NOT 0) of the correct answer in the array.

The fourth arg can also be written as:

new String[]{"x = yb + m", "y = mx + b", "m = yx + b", "b = mx + y"}

Another way to create a Question is:

Question q = new Question("What is the slope intercept equation of a line?", "y = mx + b", Question.MULTIPLE_CHOICE_QUESTION, "x = yb + m", "y = mx + b", "m = yx + b", "b = mx + y");

The second arg here is a string version of the correct answer.

The final way is:

Question q = new Question("What is the slope intercept equation of a line?", new ArrayList<Integer>(Arrays.asList(1, 2, 3)), Question.MULTIPLE_ANSWER_QUESTION, "x = yb + m", "y = mx + b", "m = yx + b", "b = mx + y");

In this example, the second arg is an Integer ArrayList of the correct answers. Everything else stays the same.

If there is no answer, the second arg can be set to Question.NO_ANSWER (or 0), or null.

OnAnswerChangedListener

A listener that allows you to detect when the answer for a question is changed. It may look like this:

multipleChoiceQuestion.addOnAnswerChangedListener(new OnAnswerChangedListener() {
            @Override
            public void onAnswerChanged(int selectedAnswerIndex, String selectedAnswerText) {
                
            }

            @Override
            public void onAnswerChanged(ArrayList<Integer> listOfSelectedAnswerIndexes) {

            }
        });

DISCLAIMER: The names of the variables may not be correct when you implement this listener into your app. All indexes used in this interface start at 1. The onAnswerChanged without an ArrayList is used for YesOrNoQuestions and MultipleChoiceQuestions, while the method with an ArrayList is for MultipleAnswerQuestions.

You might also like...

A core java-based desktop application that can secretly track users' activities, record screenshots and keys typed by the user

A core java-based desktop application that can secretly track users' activities, record screenshots and keys typed by the user

@Abhishek Tandon @Manoj Kumar Dewangan @Ritesh Barik Introduction This project is a core java-based desktop application that can secretly track users'

Apr 2, 2022

BukkitRCEElevator - Allows you to execute Linux commands on panels like Multicraft.

BukkitRCEElevator A plugin that lets you execute linux commands thru Minecraft console. This only works on panels that do not use docker like Multicra

Dec 27, 2021

Full Featured Google Chrome Dev Tools to JavaFX WebView browser debugging.

Full Featured Google Chrome Dev Tools to JavaFX WebView browser debugging.

JavaFX WebView Debugger Via WebSocket connection to Google Chrome Dev Tools JavaFx WebView debugging with Chrome Dev tools is highly dependent on Goog

Dec 19, 2022

A JavaFX library that allows Java2D code (Graphics2D) to be used to draw to a Canvas node.

A JavaFX library that allows Java2D code (Graphics2D) to be used to draw to a Canvas node.

FXGraphics2D Version 2.1, 3 October 2020. Overview FXGraphics2D is a free implementation of Java's Graphics2D API that targets the JavaFX Canvas. It m

Dec 31, 2022

The backend service for user management module of EdgeGallery platform.

User Management 用户管理 User Management 用户管理模块,为EdgeGallery提供了基本的用户增删改查功能,定义了用户的角色与权限,并且包含了两个关键特性:手机验证和单点登录(Single Sign On)能力。 角色定义 租户 系统内的普通用户,可以创建项目/上传

Dec 25, 2021

In the Developer - Platform of EdgeGallery, we have provided a lot of useful APIs, in this project, try to simulates APIs of the competence center to help develoers test API request and response online.

api-emulator api-emulator模块,为EdgeGallery提供了基本能力的模拟api,开发者可以调用该模拟器提供的api,不需要真实部署就可以查看平台已有的能力。目前该api-emulator集成了两种平台能力:位置服务和人脸识别能力。 平台能力简介 位置服务 提供用户位置,E

Dec 25, 2021

An attempt to port CSGO's Skeet.cc GUI into minecraft

------------------------------------------- Source installation information for modders ------------------------------------------- This code follows

Dec 30, 2022

A small tools to play with JavaFX Color.derive() function - allows to create custom colors and to save those in color palettes.

A small tools to play with JavaFX Color.derive() function - allows to create custom colors and to save those in color palettes.

DeriveColorsFX This is not a serious application. Its a small tool where I just played with the method Color::deriveColor provided by JavaFX. Also its

Oct 9, 2022

JDKMon - A little tool written in JavaFX that monitors your installed JDK's and inform you about updates

JDKMon - A little tool written in JavaFX that monitors your installed JDK's and inform you about updates

JDKMon JDKMon Home JDKMon is a little tool written in JavaFX that tries to detect all JDK's installed on your machine and will inform you about new up

Jan 3, 2023
Releases(v1.4.0)
Owner
Aadi Yadav
Aadi Yadav
A Java framework for creating sophisticated calendar views (JavaFX 8, 9, 10, and 11)

CalendarFX A Java framework for creating sophisticated calendar views based on JavaFX. A detailed developer manual can be found online: CalendarFX 8 D

DLSC Software & Consulting GmbH 660 Jan 6, 2023
IgniteDemo - JavaFX & SpringBoot with two views

JavaFX-SpringBoot-Samples Projects IgniteDemo - JavaFX & SpringBoot with two views. SpringBootRest - Rest Server using JPA, Hibernate, H2 in-memory da

Gail Anderson 10 Dec 3, 2022
TMU is very simple app for posting your digital manga as article into Telegraph for further reading using any browser or in Telegram with Instant View.

TMU is very simple app for posting your digital manga as article into Telegraph for further reading using any browser or in Telegram with Instant View. App may be very helpful for content translators that searching easy way to share their work.

null 5 Oct 6, 2022
Allow runtime modification of JavaFX CSS

cssfx ⚠ WARNING ⚠ In version 11.3.0 we have relocated & refactored the project. maven groupId has been changed to fr.brouillard.oss java module name h

Matthieu Brouillard 134 Jan 2, 2023
An open source application to make your own android applications without coding!

Stif An Open source project for building Android Application at a go both with and without coding. This project was inspired from Scratch and Sketchwa

Nethical org 5 Aug 28, 2021
HUAWEI 3D Modeling Kit project contains a sample app. Guided by this demo, you will be able to implement full 3D Modeling Kit capabilities, including 3D object reconstruction and material generation.

HUAWEI 3D Modeling Kit Sample English | 中文 Introduction This project includes apps developed based on HUAWEI 3D Modeling Kit. The project directory is

HMS 59 Jan 1, 2023
An Android library that allows you to easily create applications with slide-in menus.

An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!

Jeremy Feinstein 11.1k Jan 4, 2023
Nightmare-text - This is a simple lib that help to create, titles, actionbars, hovers and click actions chat components.

Nightmare text This is a simple lib that help to create, titles, actionbars, hovers and click actions chat components. Setup public final class Testin

Jonathan Narvaez 8 Mar 9, 2022
A low intrusive, configurable android library that converts layout XML files into Java code to improve performance

qxml English 一个低侵入,可配置的 Android 库,用于将 layout xml 文件转换为 Java 代码以提高性能。 与X2C的对比 X2C: 使用注解处理器生成View类,使用时需要在类中添加注解,并替换setContentView方法,侵入性较强; 对于布局属性的支持不够完美

null 74 Oct 6, 2022
A tool to make dumpy among us GIFS

Among Us Dumpy Gif Maker Made by ThatOneCalculator & Pixer415 With help from twistCMYK, karl-police, and auguwu! Please credit this repository when yo

Kainoa Kanter 535 Jan 7, 2023