Skip to content

Commit 32bc705

Browse files
committed
Added getOptions method
1 parent 3db5370 commit 32bc705

File tree

3 files changed

+28
-36
lines changed

3 files changed

+28
-36
lines changed

CheckboxQuestion/CheckboxQuestion/src/main/java/com/aadyad/checkboxquestion/Views/MultipleAnswerQuestion.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class MultipleAnswerQuestion extends LinearLayout {
3030
public static final int RIGHT = 2;
3131
Context context;
3232

33+
String[] allOptions;
34+
3335
private OnAnswerChangedListener onAnswerChangedListener;
3436

3537
ArrayList<CheckBox> checkBoxes = new ArrayList<>();
@@ -102,6 +104,7 @@ public void init(String title, String number, boolean numEnabled, int spacing, i
102104
mainLayout = findViewById(R.id.mainLayout);
103105

104106
this.spacing = spacing;
107+
this.allOptions = options;
105108

106109
checkBoxes.add(option1);
107110
checkBoxes.add(option2);
@@ -508,4 +511,8 @@ public void setCheckedOption(String option){
508511
}
509512
}
510513
}
514+
515+
public String[] getOptions(){
516+
return allOptions;
517+
}
511518
}

CheckboxQuestion/CheckboxQuestion/src/main/java/com/aadyad/checkboxquestion/Views/MultipleChoiceQuestion.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class MultipleChoiceQuestion extends LinearLayout {
2727
public static final int LEFT = 0;
2828
public static final int CENTER = 1;
2929
public static final int RIGHT = 2;
30+
String[] allOptions;
3031
Context context;
3132

3233
private OnAnswerChangedListener onAnswerChangedListener;
@@ -98,6 +99,7 @@ public void init(String title, String number, boolean numEnabled, int spacing, i
9899
mainLayout = findViewById(R.id.mainLayout);
99100

100101
this.spacing = spacing;
102+
this.allOptions = options;
101103

102104
checkBoxes.add(option1);
103105
checkBoxes.add(option2);
@@ -511,4 +513,8 @@ public void setCheckedOption(String option) {
511513
}
512514
}
513515
}
516+
517+
public String[] getOptions(){
518+
return allOptions;
519+
}
514520
}

CheckboxQuestion/app/src/main/java/com/aadyad/checkboxquestions_library/MainActivity.java

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import com.aadyad.checkboxquestion.Question;
1313
import com.aadyad.checkboxquestion.QuestionList;
1414
import com.aadyad.checkboxquestion.QuestionListSettings;
15+
import com.aadyad.checkboxquestion.Views.MultipleAnswerQuestion;
1516
import com.aadyad.checkboxquestion.Views.MultipleChoiceQuestion;
17+
import com.aadyad.checkboxquestion.Views.YesOrNoQuestion;
1618

1719
import org.json.JSONArray;
1820
import org.json.JSONException;
@@ -108,42 +110,19 @@ public void run() {
108110
questionList = new QuestionList(list, questionListSettings, getApplicationContext());
109111
questionList.createQuestionViews();
110112

111-
questionList.addOnAnswerChangedListener(0, new OnAnswerChangedListener() {
112-
@Override
113-
public void onAnswerChanged(int answer, String answerText) {
114-
Toast.makeText(MainActivity.this, "Answer: " + answer + answerText, Toast.LENGTH_SHORT).show();
115-
}
116-
117-
@Override
118-
public void onAnswerChanged(ArrayList<Integer> answer) {
119-
120-
}
121-
});
122-
123-
questionList.addOnAnswerChangedListener(21, new OnAnswerChangedListener() {
124-
@Override
125-
public void onAnswerChanged(int answer, String answerText) {
126-
Toast.makeText(MainActivity.this, "Answer: " + answer + answerText, Toast.LENGTH_SHORT).show();
127-
128-
}
129-
130-
@Override
131-
public void onAnswerChanged(ArrayList<Integer> answer) {
132-
133-
}
134-
});
135-
136-
questionList.addOnAnswerChangedListener(20, new OnAnswerChangedListener() {
137-
@Override
138-
public void onAnswerChanged(int answer, String answerText) {
139-
140-
}
141-
142-
@Override
143-
public void onAnswerChanged(ArrayList<Integer> answer) {
144-
Toast.makeText(MainActivity.this, "Answer: " + answer, Toast.LENGTH_SHORT).show();
145-
}
146-
});
113+
for (int i = 0; i < questionList.getQuestionViews().getChildCount(); i++){
114+
questionList.addOnAnswerChangedListener(i, new OnAnswerChangedListener() {
115+
@Override
116+
public void onAnswerChanged(int selectedAnswerIndex, String selectedAnswerText) {
117+
Toast.makeText(MainActivity.this, "Selected: " + selectedAnswerText, Toast.LENGTH_SHORT).show();
118+
}
119+
120+
@Override
121+
public void onAnswerChanged(ArrayList<Integer> listOfSelectedAnswerIndexes) {
122+
Toast.makeText(MainActivity.this, "Selected: " + listOfSelectedAnswerIndexes, Toast.LENGTH_SHORT).show();
123+
}
124+
});
125+
}
147126

148127
linearLayout.addView(questionList.getQuestionViews());
149128
}

0 commit comments

Comments
 (0)