Android 将数据库内容列表获取为字符串
我想用viewpager在问题之间滑动 1) 我可以使用自定义页面,如(“text1”、“text2”、“text3”、“text4”)和以下代码: 在pageadapter中:Android 将数据库内容列表获取为字符串,android,android-fragments,android-viewpager,Android,Android Fragments,Android Viewpager,我想用viewpager在问题之间滑动 1) 我可以使用自定义页面,如(“text1”、“text2”、“text3”、“text4”)和以下代码: 在pageadapter中: protected static final String[] CONTENT = new String[] { "text1", "text2", "text3, "text4", }; 1) 但我无法将数据库中的数据转换为字符串,如: new String[] { "myquestion1", "myquest
protected static final String[] CONTENT = new String[] { "text1", "text2", "text3, "text4", };
1) 但我无法将数据库中的数据转换为字符串,如:
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);
}
/**
*
*/
公共视图(){
此.manageView(true);
}
/**
*更新用户界面
*
*@param start这是否是测验的开始
*/
@抑制警告(“装箱”)
公共void manageView(最终布尔启动){
if(QuizActivity.ll.getChildCount()>0){
quizaActivity.ll.removeAllViews();
quizaActivity.ll.addView(quizaActivity.questionText);
}
quizaActivity.warning.setVisibility(View.INVISIBLE);
QuizActivity.warningIcon.setVisibility(View.INVISIBLE);
if(this.q.isReviewing()){
quizaActivity.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);
}否则{
QuizActivity.warning.setText(R.string.error);
QuizActivity.warning.setTextColor(Statics.badColor);
QuizActivity.warningIcon.setImageResource(R.drawable.error);
}
}
quizaActivity.back.setEnabled((!start | | this.q.isBackAllowed())
&&(!this.q.isFirstQuestion());
if(this.q.isLastQuestion()){
QuizActivity.next.setText(R.string.finish);
QuizActivity.next.setCompoundDrawableSwithinInstructBounds(null,null,
this.getResources().getDrawable(R.drawable.finish_测验),null);
}否则{
QuizActivity.next.setText(R.string.next);
QuizActivity.next.setCompoundDrawableSwithinInstructBounds(null,null,
this.getResources().getDrawable(R.drawable.arrow_right),null);
}
quizaActivity.review.setChecked(this.q.getCurrentQuestion().isMarkedForReview());
if(this.q.isReviewing()){
quizaActivity.review.setVisibility(View.GONE);
if((null!=this.q.getCurrentQuestion().getExplauration())
&&(this.q.getCurrentQuestion().getExpression().length()>0)){
quizaActivity.explain.setVisibility(View.VISIBLE);
}否则{
quizaActivity.explain.setVisibility(View.GONE);
}
}
QuizActivity.progress.setText(this.getString(R.string.q)+“”
+此.q.getCurrentQuestionNumber()+“/”
+这是.q.getQuestionCount());
quizaActivity.title.setText(this.q.getCategory().getParentCategoryTitle()+“-”
+这个.q.getCategory().getCategoryTitle());
quizaActivity.questionText.setText(this.q.getCurrentQuestion().getQuestionText());
if(此.q.isShowAmountAnswers()){
quizaActivity.questionText.append(“(”+this.getString(R.string.select)+
“+this.q.getCurrentQuestion().getAmountCorrectAnswers()+”);
}
this.userAnswers=this.q.getCurrentQuestion().getUserAnswers();
this.answers=新建LinkedList();
如果(!this.q.isShowAmountAnswers()
||(此.q.getCurrentQuestion().getAmountCorrectAnswers()>1)){
对于(最终答案ans:this.q.getCurrentQuestion().getAnswers()){
this.answers.add(新复选框(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);
如果(ans.isAnswerCorrect()){
this.answers.getLast().setTextColor(静态
.goodColor);
}否则{
this.answers.getLast().setTextColor(静态
(颜色不好);
}
}
quizaActivity.ll.addView(this.answers.getLast());
}
}否则{
最终射线组rg=新射线组(本);
对于(最终答案ans:this.q.getCurrentQuestion().getAnswers()){
this.answers.add(新单选按钮(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);
如果(ans.isAnswerCorrect()){
this.answers.getLast().setTextColor(静态
.goodColor);
}否则{
this.answers.getLast().setTextColor(静态
(颜色不好);
}
}
this.answers.getLast()
.setOnCheckedChangeListener(新的OnCheckedChangeListener(){
@抑制警告(“合成访问”)
@凌驾
检查更改后的公共无效(最终合成按钮视图,
最终布尔值(已检查){
for(最终视图rb:QuizActivity.this.answers)
{
((复合按钮)rb).setChecked(false);
}
按钮视图集