获取数据库内容列表到字符串

时间:2013-03-11 22:43:20

标签: android android-fragments android-viewpager

我想用viewpager

在问题之间滑动

1)我可以使用以下代码使用自定义页面(“text1”,“text2”,“text3,”text4“): 在pageadapter中:

 protected static final String[] CONTENT = new String[] { "text1", "text2", "text3, "text4", };

1)但是我无法将数据从数据库传递到String,如:

new String[] { "myquestion1", "myquestion2", ....... "my lastquestion", }

在我的测验活动中:

/**
     * 
     */
    public void initView() {
        this.manageView(true);
    }

    /**
     * updates the user interface
     * 
     * @param start whether this is the start of the quiz
     */
    @SuppressWarnings("boxing")
    public void manageView(final boolean start) {
        if (QuizActivity.ll.getChildCount() > 0) {
            QuizActivity.ll.removeAllViews();
            QuizActivity.ll.addView(QuizActivity.questionText);
        }

        QuizActivity.warning.setVisibility(View.INVISIBLE);
        QuizActivity.warningIcon.setVisibility(View.INVISIBLE);
        if (this.q.isReviewing()) {
            QuizActivity.warning.setVisibility(View.VISIBLE);
            QuizActivity.warningIcon.setVisibility(View.VISIBLE);
            if (this.q.getCurrentQuestion().isAnsweredCorrect()) {
                QuizActivity.warning.setText(R.string.correct);
                QuizActivity.warning.setTextColor(Statics.goodColor);
                QuizActivity.warningIcon.setImageResource(R.drawable.correct);
            } else {
                QuizActivity.warning.setText(R.string.wrong);
                QuizActivity.warning.setTextColor(Statics.badColor);
                QuizActivity.warningIcon.setImageResource(R.drawable.wrong);
            }
        }
        QuizActivity.back.setEnabled((!start || this.q.isBackAllowed())
                && (!this.q.isFirstQuestion()));
        if (this.q.isLastQuestion()) {
            QuizActivity.next.setText(R.string.finish);
            QuizActivity.next.setCompoundDrawablesWithIntrinsicBounds(null, null,
                    this.getResources().getDrawable(R.drawable.finish_quiz), null);
        } else {
            QuizActivity.next.setText(R.string.next);

            QuizActivity.next.setCompoundDrawablesWithIntrinsicBounds(null, null,
                    this.getResources().getDrawable(R.drawable.arrow_right), null);
        }
        QuizActivity.review.setChecked(this.q.getCurrentQuestion().isMarkedForReview());
        if (this.q.isReviewing()) {
            QuizActivity.review.setVisibility(View.GONE);
            if ((null != this.q.getCurrentQuestion().getExplanation())
                    && (this.q.getCurrentQuestion().getExplanation().length() > 0)) {
                QuizActivity.explain.setVisibility(View.VISIBLE);
            } else {
                QuizActivity.explain.setVisibility(View.GONE);
            }
        }
        QuizActivity.progress.setText(this.getString(R.string.q_) + " "
                + this.q.getCurrentQuestionNumber() + "/"
                + this.q.getQuestionCount());
        QuizActivity.title.setText(this.q.getCategory().getParentCategoryTitle() + " - "
                + this.q.getCategory().getCategoryTitle());
        QuizActivity.questionText.setText(this.q.getCurrentQuestion().getQuestionText());
        if (this.q.isShowAmountAnswers()) {
            QuizActivity.questionText.append(" (" + this.getString(R.string.select) +
                    " " + this.q.getCurrentQuestion().getAmountCorrectAnswers() + ")");
        }
        this.userAnswers = this.q.getCurrentQuestion().getUserAnswers();
        this.answers = new LinkedList<CompoundButton>();

        if (!this.q.isShowAmountAnswers()
                || (this.q.getCurrentQuestion().getAmountCorrectAnswers() > 1)) {

            for (final Answer ans : this.q.getCurrentQuestion().getAnswers()) {
                this.answers.add(new CheckBox(this));
                this.answers.getLast().setText(ans.getAnswerText());
                this.answers.getLast().setId(ans.getAnswerId());
                this.answers.getLast().setChecked(this.userAnswers.get(ans.getAnswerId()));
                if (this.q.isReviewing()) {
                    this.answers.getLast().setEnabled(false);
                    if (ans.isAnswerCorrect()) {
                        this.answers.getLast().setTextColor(Statics
                                .goodColor);
                    } else {
                        this.answers.getLast().setTextColor(Statics
                                .badColor);
                    }
                }
                QuizActivity.ll.addView(this.answers.getLast());
            }
        } else {
            final RadioGroup rg = new RadioGroup(this);

            for (final Answer ans : this.q.getCurrentQuestion().getAnswers()) {
                this.answers.add(new RadioButton(this));
                this.answers.getLast().setText(ans.getAnswerText());
                this.answers.getLast().setId(ans.getAnswerId());
                this.answers.getLast().setChecked(this.userAnswers.get(ans.getAnswerId()));
                if (this.q.isReviewing()) {

                    this.answers.getLast().setEnabled(false);
                    if (ans.isAnswerCorrect()) {
                        this.answers.getLast().setTextColor(Statics
                                .goodColor);
                    } else {
                        this.answers.getLast().setTextColor(Statics
                                .badColor);
                    }
                }
                this.answers.getLast()
                        .setOnCheckedChangeListener(new OnCheckedChangeListener() {
                            @SuppressWarnings("synthetic-access")
                            @Override
                            public void onCheckedChanged(final CompoundButton buttonView,
                                    final boolean isChecked) {
                                for (final View rb : QuizActivity.this.answers)
                        {
                            ((CompoundButton) rb).setChecked(false);
                        }
                        buttonView.setChecked(isChecked);
                    }
                        });
                rg.addView(this.answers.getLast());
            }
            QuizActivity.ll.addView(rg);
        }

        QuizActivity.next.setOnClickListener(this);
        QuizActivity.back.setOnClickListener(this);
        QuizActivity.explain.setOnClickListener(this);
    }

那么如何将我的问题列表应用于“new String [] {...,...,...}”

0 个答案:

没有答案