0

Here I'm trying to make a quiz application without using databases (requirement). Each question has 4 options.

I had made a class for Questions. Now, in the activity in which I want to show my data, I'm unable to get method to fetch the data from the QuestionModelClass.

I had made 2D Array but it gets more complicated to get it. Is there any way to bind 3 of the classes (QuestionModelClass, Adapter class, and Activity class)?

public class QuestionsModelClass {

private String sQuestion;
private String sRightAnswer;
private List<String> sOptions;

QuestionsModelClass(){
    sQuestion = null;
    sRightAnswer = null;
    sOptions = null;
}

public QuestionsModelClass(String sQuestion, String sRightAnswer, List<String> sOptions) {
    this.sQuestion = sQuestion;
    this.sRightAnswer = sRightAnswer;
    this.sOptions = sOptions;
}

public String getsQuestion() {
    return sQuestion;
}

public void setsQuestion(String sQuestion) {

    this.sQuestion = sQuestion;
}

public String getsRightAnswer() {

    return sRightAnswer;
}

public void setsRightAnswer(String sRightAnswer) {
    this.sRightAnswer = sRightAnswer;
}

public List<String> getsOptions() {

    return sOptions;
}

public void setsOptions(List<String> sOptions) {

    this.sOptions = sOptions;
}
}

And my Adapter Class

public class QuizAdapter extends BaseAdapter {
private Context context;
private List<QuestionsModelClass> questionClassList;

private String[][] options;

private LayoutInflater inflater;

private QuizAdapter(Context c, List<QuestionsModelClass> l){
    this.context= c;
    this.questionClassList = l;
    inflater = LayoutInflater.from(context);
}

@Override
public int getCount() {
    return  questionClassList.size();

}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    convertView = inflater.inflate(R.layout.questionpattern, parent,false);
    QuestionsModelClass questions = questionClassList.get(position);

    TextView quesText= convertView.findViewById(R.id.questionTextView);
    RadioButton radioButtonA = convertView.findViewById(R.id.optionA);
    RadioButton radioButtonB = convertView.findViewById(R.id.optionB);
    RadioButton radioButtonC = convertView.findViewById(R.id.optionC);
    RadioButton radioButtonD = convertView.findViewById(R.id.optionD);

    return convertView;
}

And this is the Activity class in which I am trying to implement all the functions

public class QuizActivity extends Activity {

final Context context= this;
private List<QuestionsModelClass> classObject;
Button okayButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_quiz);


   String[] question= new String[]{"Q1. ABDE", "Q2. ADDASD"};
    String[][] op;
    String[] right = new String[]{"abc","def"};
    classObject = new ArrayList<>();
    op= new String[][]{
            {"a1", "2", "3", "4"},
            {"b1","b2","b3","b4"}};

    final Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.customdialoguebox);
    dialog.show();


    okayButton = (Button) dialog.findViewById(R.id.okayButton);
    okayButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(QuizActivity.this,"Good Luck!", Toast.LENGTH_SHORT).show();
                dialog.cancel();
        }
    });


}
Wajiha
  • 37
  • 6
  • What is the problem now? Where is the code of your Activity?? – Ravi Dec 21 '17 at 14:51
  • The problem is I'm unable to bind it with the Activity class.. I had made list private List classObject; but it doesn't allows to set/get data from the Question class @shravani – Wajiha Dec 21 '17 at 14:53
  • Show your activity – Ravi Dec 21 '17 at 15:02
  • I have added in the Question now @shravani – Wajiha Dec 21 '17 at 15:05
  • Let me brief my problem a bit more. I want to set an array for using 'QuestionClassModel' via Adapter (cause there will be more operartion has to be performed on them). Can you suggest any tutorial or way through which I can set and get Questions to my Activity (for display) – Wajiha Dec 21 '17 at 15:20
  • Please look into this link for reference - [Display List In Alert Dialog](https://stackoverflow.com/questions/15762905/how-can-i-display-a-list-view-in-an-android-alert-dialog) – Ravi Dec 21 '17 at 15:20
  • How can I use 2D array for options? @shravani – Wajiha Dec 21 '17 at 15:29

0 Answers0