Android考试系统
最近没事做一点开发练练手吧,复习一下Android基础知识,没事写demo总是好的,先看看效果图吧下面是布局代码了,从图片上面看出中间是一个viewpager 通过点击上一题和下一题来切换题目,。<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="
·
最近没事做一点开发练练手吧,复习一下Android基础知识,没事写demo总是好的,先看看效果图吧
下面是布局代码了,从图片上面看出中间是一个viewpager 通过点击上一题和下一题来切换题目,。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eaeaea" >
<LinearLayout
android:id="@+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#288df5" >
<LinearLayout
android:id="@+id/activity_prepare_test_upLayout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/home_menu_margin_5"
android:src="@drawable/ic_practice_up_subject" />
<TextView
style="@style/menu_bottom_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/home_menu_margin_8"
android:layout_marginTop="@dimen/home_menu_margin_5"
android:text="上一题" />
</LinearLayout>
<LinearLayout
android:id="@+id/activity_prepare_test_totalLayout"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/home_menu_margin_5"
android:src="@drawable/ic_practice_tatal_index" />
<TextView
android:id="@+id/activity_prepare_test_totalTv"
style="@style/menu_bottom_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/home_menu_margin_8"
android:layout_marginTop="@dimen/home_menu_margin_5"
android:text="4/32" />
</LinearLayout>
<LinearLayout
android:id="@+id/activity_prepare_test_errorLayout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/menu_bottom_errorIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/home_menu_margin_5"
android:src="@drawable/ic_practice_test_error" />
<TextView
android:id="@+id/menu_bottom_errorTV"
style="@style/menu_bottom_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/home_menu_margin_8"
android:layout_marginTop="@dimen/home_menu_margin_5"
android:text="我的错题" />
</LinearLayout>
<LinearLayout
android:id="@+id/activity_prepare_test_nextLayout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/menu_bottom_nextIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/home_menu_margin_5"
android:src="@drawable/ic_practice_next_subject" />
<TextView
android:id="@+id/menu_bottom_nextTV"
style="@style/menu_bottom_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/home_menu_margin_8"
android:layout_marginTop="@dimen/home_menu_margin_5"
android:text="下一题" />
</LinearLayout>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/bottom_layout"
android:layout_margin="@dimen/margin_10"
android:background="@color/white"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/margin_10" >
<TextView
android:id="@+id/activity_prepare_test_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/home_menu_margin_8"
android:textColor="@color/practice_test_no_text"
android:textSize="16sp"
/>
<TextView
android:id="@+id/activity_prepare_test_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/home_menu_margin_8"
android:textColor="@color/practice_test_content_text"
android:textSize="16sp" />
</LinearLayout>
<!-- 单选 -->
<LinearLayout
android:id="@+id/activity_prepare_test_radioBtnLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="@dimen/margin_10"
>
<LinearLayout
android:id="@+id/activity_prepare_test_layout_a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="@drawable/answer_choose_bg"
android:padding="@dimen/home_menu_margin_8" >
<ImageView
android:id="@+id/vote_submit_select_image_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_practice_test_normal" />
<TextView
android:id="@+id/vote_submit_select_text_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/home_menu_margin_8"
android:text="您给出的回答选项?"
android:textSize="16sp"
android:textColor="@color/practice_test_result_text"
/>
<ImageView
android:id="@+id/vote_submit_select_image_a_"
android:layout_width="150dip"
android:layout_height="75dip"
android:src="@drawable/ic_practice_test_normal"
android:visibility="gone"
android:layout_marginLeft="@dimen/home_menu_margin_8"
android:scaleType="fitXY"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/activity_prepare_test_layout_b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="@drawable/answer_choose_bg"
android:padding="@dimen/home_menu_margin_8" >
<ImageView
android:id="@+id/vote_submit_select_image_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_practice_test_normal" />
<TextView
android:id="@+id/vote_submit_select_text_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/home_menu_margin_8"
android:text="您给出的回答选项?"
android:textSize="16sp"
android:textColor="@color/practice_test_result_text" />
<ImageView
android:id="@+id/vote_submit_select_image_b_"
android:layout_width="150dip"
android:layout_height="75dip"
android:src="@drawable/ic_practice_test_normal"
android:visibility="gone"
android:layout_marginLeft="@dimen/home_menu_margin_8"
android:scaleType="fitXY"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/activity_prepare_test_layout_c"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="@drawable/answer_choose_bg"
android:padding="@dimen/home_menu_margin_8" >
<ImageView
android:id="@+id/vote_submit_select_image_c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_practice_test_normal" />
<TextView
android:id="@+id/vote_submit_select_text_c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/home_menu_margin_8"
android:text="您给出的回答选项?"
android:textSize="16sp"
android:textColor="@color/practice_test_result_text" />
<ImageView
android:id="@+id/vote_submit_select_image_c_"
android:layout_width="150dip"
android:layout_height="75dip"
android:src="@drawable/ic_practice_test_normal"
android:visibility="gone"
android:layout_marginLeft="@dimen/home_menu_margin_8"
android:scaleType="fitXY"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/activity_prepare_test_layout_d"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="@drawable/answer_choose_bg"
android:padding="@dimen/home_menu_margin_8" >
<ImageView
android:id="@+id/vote_submit_select_image_d"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_practice_test_normal" />
<TextView
android:id="@+id/vote_submit_select_text_d"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/home_menu_margin_8"
android:text="您给出的回答选项?"
android:textSize="16sp"
android:textColor="@color/practice_test_result_text" />
<ImageView
android:id="@+id/vote_submit_select_image_d_"
android:layout_width="150dip"
android:layout_height="75dip"
android:src="@drawable/ic_practice_test_normal"
android:visibility="gone"
android:layout_marginLeft="@dimen/home_menu_margin_8"
android:scaleType="fitXY"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/activity_prepare_test_layout_e"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="@drawable/answer_choose_bg"
android:padding="@dimen/home_menu_margin_8" >
<ImageView
android:id="@+id/vote_submit_select_image_e"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_practice_test_normal" />
<TextView
android:id="@+id/vote_submit_select_text_e"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/home_menu_margin_8"
android:text="您给出的回答选项?"
android:textSize="16sp"
android:textColor="@color/practice_test_result_text" />
<ImageView
android:id="@+id/vote_submit_select_image_e_"
android:layout_width="150dip"
android:layout_height="75dip"
android:src="@drawable/ic_practice_test_normal"
android:visibility="gone"
android:layout_marginLeft="@dimen/home_menu_margin_8"
android:scaleType="fitXY"
/>
</LinearLayout>
</LinearLayout>
<!-- 错题分析 -->
<LinearLayout
android:id="@+id/activity_prepare_test_wrongLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginTop="@dimen/btn_height"
android:orientation="vertical"
android:padding="@dimen/margin_10"
android:visibility="gone"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/ic_practice_test_analyze" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_15"
android:background="@drawable/ic_practice_test_explaindetail"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/activity_prepare_test_explaindetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/practice_test_result_detail_text" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
布局又了,就要写适配器了,适配器里面有各种逻辑判断,
package com.example.answer.adapter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.example.answer.AnalogyExaminationActivity;
import com.example.answer.MyErrorQuestionActivity;
import com.example.answer.R;
import com.example.answer.R.drawable;
import com.example.answer.R.id;
import com.example.answer.bean.AnSwerInfo;
import com.example.answer.bean.ErrorQuestionInfo;
import com.example.answer.bean.SaveQuestionInfo;
import com.example.answer.database.DBManager;
import com.example.answer.util.ConstantUtil;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.v4.view.PagerAdapter;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
@SuppressLint("UseSparseArrays")
public class ExaminationSubmitAdapter extends PagerAdapter {
AnalogyExaminationActivity mContext;
// 传递过来的页面view的集合
List<View> viewItems;
// 每个item的页面view
View convertView;
// 传递过来的所有数据
List<AnSwerInfo> dataItems;
String imgServerUrl="";
@SuppressLint("UseSparseArrays")
private Map<Integer, Boolean> map = new HashMap<Integer, Boolean>();
@SuppressLint("UseSparseArrays")
private Map<Integer, Boolean> mapClick = new HashMap<Integer, Boolean>();
private Map<Integer, String> mapMultiSelect = new HashMap<Integer, String>();
boolean isClick=false;
boolean isNext = false;
StringBuffer answer=new StringBuffer();
StringBuffer answerLast=new StringBuffer();
StringBuffer answer1=new StringBuffer();
DBManager dbManager;
String isCorrect=ConstantUtil.isCorrect;//1对,0错
int errortopicNum=0;
String resultA="";
String resultB="";
String resultC="";
String resultD="";
String resultE="";
public ExaminationSubmitAdapter(AnalogyExaminationActivity context, List<View> viewItems, List<AnSwerInfo> dataItems,String imgServerUrl) {
mContext = context;
this.viewItems = viewItems;
this.dataItems = dataItems;
this.imgServerUrl = imgServerUrl;
dbManager = new DBManager(context);
dbManager.openDB();
}
public long getItemId(int position) {
return position;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView(viewItems.get(position));
}
@Override
public Object instantiateItem(ViewGroup container,final int position) {
final ViewHolder holder = new ViewHolder();
convertView = viewItems.get(position);
holder.questionType = (TextView) convertView.findViewById(R.id.activity_prepare_test_no);
holder.question = (TextView) convertView.findViewById(R.id.activity_prepare_test_question);
holder.previousBtn = (LinearLayout) convertView.findViewById(R.id.activity_prepare_test_upLayout);
holder.nextBtn = (LinearLayout) convertView.findViewById(R.id.activity_prepare_test_nextLayout);
holder.nextText = (TextView) convertView.findViewById(R.id.menu_bottom_nextTV);
holder.errorBtn =(LinearLayout) convertView.findViewById(R.id.activity_prepare_test_errorLayout);
holder.totalText = (TextView) convertView.findViewById(R.id.activity_prepare_test_totalTv);
holder.nextImage = (ImageView) convertView.findViewById(R.id.menu_bottom_nextIV);
holder.wrongLayout = (LinearLayout) convertView.findViewById(R.id.activity_prepare_test_wrongLayout);
holder.explaindetailTv = (TextView) convertView.findViewById(R.id.activity_prepare_test_explaindetail);
holder.layoutA=(LinearLayout) convertView.findViewById(R.id.activity_prepare_test_layout_a);
holder.layoutB=(LinearLayout) convertView.findViewById(R.id.activity_prepare_test_layout_b);
holder.layoutC=(LinearLayout) convertView.findViewById(R.id.activity_prepare_test_layout_c);
holder.layoutD=(LinearLayout) convertView.findViewById(R.id.activity_prepare_test_layout_d);
holder.layoutE=(LinearLayout) convertView.findViewById(R.id.activity_prepare_test_layout_e);
holder.ivA=(ImageView) convertView.findViewById(R.id.vote_submit_select_image_a);
holder.ivB=(ImageView) convertView.findViewById(R.id.vote_submit_select_image_b);
holder.ivC=(ImageView) convertView.findViewById(R.id.vote_submit_select_image_c);
holder.ivD=(ImageView) convertView.findViewById(R.id.vote_submit_select_image_d);
holder.ivE=(ImageView) convertView.findViewById(R.id.vote_submit_select_image_e);
holder.tvA=(TextView) convertView.findViewById(R.id.vote_submit_select_text_a);
holder.tvB=(TextView) convertView.findViewById(R.id.vote_submit_select_text_b);
holder.tvC=(TextView) convertView.findViewById(R.id.vote_submit_select_text_c);
holder.tvD=(TextView) convertView.findViewById(R.id.vote_submit_select_text_d);
holder.tvE=(TextView) convertView.findViewById(R.id.vote_submit_select_text_e);
holder.ivA_=(ImageView) convertView.findViewById(R.id.vote_submit_select_image_a_);
holder.ivB_=(ImageView) convertView.findViewById(R.id.vote_submit_select_image_b_);
holder.ivC_=(ImageView) convertView.findViewById(R.id.vote_submit_select_image_c_);
holder.ivD_=(ImageView) convertView.findViewById(R.id.vote_submit_select_image_d_);
holder.ivE_=(ImageView) convertView.findViewById(R.id.vote_submit_select_image_e_);
holder.totalText.setText(position+1+"/"+dataItems.size());
holder.errorBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent(mContext,MyErrorQuestionActivity.class);
mContext.startActivity(intent);
}
});
if(dataItems.get(position).getOptionA().equals("")){
holder.layoutA.setVisibility(View.GONE);
}if(dataItems.get(position).getOptionB().equals("")){
holder.layoutB.setVisibility(View.GONE);
}if(dataItems.get(position).getOptionC().equals("")){
holder.layoutC.setVisibility(View.GONE);
}if(dataItems.get(position).getOptionD().equals("")){
holder.layoutD.setVisibility(View.GONE);
}if(dataItems.get(position).getOptionE().equals("")){
holder.layoutE.setVisibility(View.GONE);
}
//判断是否文字图片题目
//文字题目
holder.ivA_.setVisibility(View.GONE);
holder.ivB_.setVisibility(View.GONE);
holder.ivC_.setVisibility(View.GONE);
holder.ivD_.setVisibility(View.GONE);
holder.ivE_.setVisibility(View.GONE);
holder.tvA.setVisibility(View.VISIBLE);
holder.tvB.setVisibility(View.VISIBLE);
holder.tvC.setVisibility(View.VISIBLE);
holder.tvD.setVisibility(View.VISIBLE);
holder.tvE.setVisibility(View.VISIBLE);
holder.tvA.setText("A." + dataItems.get(position).getOptionA());
holder.tvB.setText("B." + dataItems.get(position).getOptionB());
holder.tvC.setText("C." + dataItems.get(position).getOptionC());
holder.tvD.setText("D." + dataItems.get(position).getOptionD());
holder.tvE.setText("E." + dataItems.get(position).getOptionE());
//判断题型
if(dataItems.get(position).getQuestionType().equals("0")){
//单选题
holder.question.setText("(单选题)"+dataItems.get(position).getQuestionName());
holder.layoutA.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(map.containsKey(position)){
return;
}
map.put(position, true);
if(dataItems.get(position).getCorrectAnswer().contains("A")){
mContext.setCurrentView(position+1);
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
isCorrect=ConstantUtil.isCorrect;
}else{
isCorrect=ConstantUtil.isError;
errortopicNum+=1;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(position).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(position).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(position).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect("A");
errorQuestionInfo.setAnalysis(dataItems.get(position).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(position).getOption_type());
if(dataItems.get(position).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA().equals("")?"":imgServerUrl+dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB().equals("")?"":imgServerUrl+dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC().equals("")?"":imgServerUrl+dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD().equals("")?"":imgServerUrl+dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE().equals("")?"":imgServerUrl+dataItems.get(position).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
holder.ivA.setImageResource(R.drawable.ic_practice_test_wrong);
holder.tvA.setTextColor(Color.parseColor("#d53235"));
//提示
holder.wrongLayout.setVisibility(View.VISIBLE);
holder.explaindetailTv.setText(""+dataItems.get(position).getAnalysis());
//显示正确选项
if(dataItems.get(position).getCorrectAnswer().contains("A")){
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("B")){
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("C")){
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("D")){
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("E")){
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
}
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(position).getQuestionId());
questionInfo.setQuestionType(dataItems.get(position).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(position).getCorrectAnswer());
questionInfo.setScore(dataItems.get(position).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(position).setIsSelect("0");
}
});
holder.layoutB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(map.containsKey(position)){
return;
}
map.put(position, true);
if(dataItems.get(position).getCorrectAnswer().contains("B")){
mContext.setCurrentView(position+1);
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
isCorrect=ConstantUtil.isCorrect;
}else{
isCorrect=ConstantUtil.isError;
errortopicNum+=1;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(position).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(position).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(position).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect("B");
errorQuestionInfo.setAnalysis(dataItems.get(position).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(position).getOption_type());
if(dataItems.get(position).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA().equals("")?"":imgServerUrl+dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB().equals("")?"":imgServerUrl+dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC().equals("")?"":imgServerUrl+dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD().equals("")?"":imgServerUrl+dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE().equals("")?"":imgServerUrl+dataItems.get(position).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
holder.ivB.setImageResource(R.drawable.ic_practice_test_wrong);
holder.tvB.setTextColor(Color.parseColor("#d53235"));
//提示
holder.wrongLayout.setVisibility(View.VISIBLE);
holder.explaindetailTv.setText(""+dataItems.get(position).getAnalysis());
//显示正确选项
if(dataItems.get(position).getCorrectAnswer().contains("A")){
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("B")){
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("C")){
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("D")){
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("E")){
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
}
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(position).getQuestionId());
questionInfo.setQuestionType(dataItems.get(position).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(position).getCorrectAnswer());
questionInfo.setScore(dataItems.get(position).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(position).setIsSelect("0");
}
});
holder.layoutC.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(map.containsKey(position)){
return;
}
map.put(position, true);
if(dataItems.get(position).getCorrectAnswer().contains("C")){
mContext.setCurrentView(position+1);
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
isCorrect=ConstantUtil.isCorrect;
}else{
isCorrect=ConstantUtil.isError;
errortopicNum+=1;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(position).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(position).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(position).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect("C");
errorQuestionInfo.setAnalysis(dataItems.get(position).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(position).getOption_type());
if(dataItems.get(position).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA().equals("")?"":imgServerUrl+dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB().equals("")?"":imgServerUrl+dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC().equals("")?"":imgServerUrl+dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD().equals("")?"":imgServerUrl+dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE().equals("")?"":imgServerUrl+dataItems.get(position).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
holder.ivC.setImageResource(R.drawable.ic_practice_test_wrong);
holder.tvC.setTextColor(Color.parseColor("#d53235"));
//提示
holder.wrongLayout.setVisibility(View.VISIBLE);
holder.explaindetailTv.setText(""+dataItems.get(position).getAnalysis());
//显示正确选项
if(dataItems.get(position).getCorrectAnswer().contains("A")){
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("B")){
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("C")){
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("D")){
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("E")){
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
}
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(position).getQuestionId());
questionInfo.setQuestionType(dataItems.get(position).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(position).getCorrectAnswer());
questionInfo.setScore(dataItems.get(position).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(position).setIsSelect("0");
}
});
holder.layoutD.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(map.containsKey(position)){
return;
}
map.put(position, true);
if(dataItems.get(position).getCorrectAnswer().contains("D")){
mContext.setCurrentView(position+1);
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
isCorrect=ConstantUtil.isCorrect;
}else{
isCorrect=ConstantUtil.isError;
errortopicNum+=1;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(position).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(position).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(position).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect("D");
errorQuestionInfo.setAnalysis(dataItems.get(position).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(position).getOption_type());
if(dataItems.get(position).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA().equals("")?"":imgServerUrl+dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB().equals("")?"":imgServerUrl+dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC().equals("")?"":imgServerUrl+dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD().equals("")?"":imgServerUrl+dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE().equals("")?"":imgServerUrl+dataItems.get(position).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
holder.ivD.setImageResource(R.drawable.ic_practice_test_wrong);
holder.tvD.setTextColor(Color.parseColor("#d53235"));
//提示
holder.wrongLayout.setVisibility(View.VISIBLE);
holder.explaindetailTv.setText(""+dataItems.get(position).getAnalysis());
//显示正确选项
if(dataItems.get(position).getCorrectAnswer().contains("A")){
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("B")){
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("C")){
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("D")){
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("E")){
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
}
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(position).getQuestionId());
questionInfo.setQuestionType(dataItems.get(position).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(position).getCorrectAnswer());
questionInfo.setScore(dataItems.get(position).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(position).setIsSelect("0");
}
});
holder.layoutE.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(map.containsKey(position)){
return;
}
map.put(position, true);
if(dataItems.get(position).getCorrectAnswer().contains("E")){
mContext.setCurrentView(position+1);
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
isCorrect=ConstantUtil.isCorrect;
}else{
isCorrect=ConstantUtil.isError;
errortopicNum+=1;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(position).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(position).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(position).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect("E");
errorQuestionInfo.setAnalysis(dataItems.get(position).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(position).getOption_type());
if(dataItems.get(position).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA().equals("")?"":imgServerUrl+dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB().equals("")?"":imgServerUrl+dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC().equals("")?"":imgServerUrl+dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD().equals("")?"":imgServerUrl+dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE().equals("")?"":imgServerUrl+dataItems.get(position).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
holder.ivE.setImageResource(R.drawable.ic_practice_test_wrong);
holder.tvE.setTextColor(Color.parseColor("#d53235"));
//提示
holder.wrongLayout.setVisibility(View.VISIBLE);
holder.explaindetailTv.setText(""+dataItems.get(position).getAnalysis());
//显示正确选项
if(dataItems.get(position).getCorrectAnswer().contains("A")){
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("B")){
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("C")){
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("D")){
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("E")){
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
}
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(position).getQuestionId());
questionInfo.setQuestionType(dataItems.get(position).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(position).getCorrectAnswer());
questionInfo.setScore(dataItems.get(position).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(position).setIsSelect("0");
}
});
}else if(dataItems.get(position).getQuestionType().equals("1")){
//多选题
holder.question.setText("(多选题)"+dataItems.get(position).getQuestionName());
holder.layoutA.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
mapClick.put(position, true);
if(map.containsKey(position)){
return;
}
if(dataItems.get(position).getCorrectAnswer().contains("A")){
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
isCorrect=ConstantUtil.isCorrect;
if(position==viewItems.size()-1){
answerLast.append("A");
}else{
answer.append("A");
}
}else{
isCorrect=ConstantUtil.isError;
mapMultiSelect.put(position, isCorrect);
errortopicNum+=1;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(position).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(position).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(position).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect("A");
errorQuestionInfo.setAnalysis(dataItems.get(position).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(position).getOption_type());
if(dataItems.get(position).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA().equals("")?"":imgServerUrl+dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB().equals("")?"":imgServerUrl+dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC().equals("")?"":imgServerUrl+dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD().equals("")?"":imgServerUrl+dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE().equals("")?"":imgServerUrl+dataItems.get(position).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
map.put(position, true);
holder.ivA.setImageResource(R.drawable.ic_practice_test_wrong);
holder.tvA.setTextColor(Color.parseColor("#d53235"));
//提示
holder.wrongLayout.setVisibility(View.VISIBLE);
holder.explaindetailTv.setText(""+dataItems.get(position).getAnalysis());
//显示正确选项
if(dataItems.get(position).getCorrectAnswer().contains("A")){
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("B")){
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("C")){
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("D")){
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("E")){
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(position).getQuestionId());
questionInfo.setQuestionType(dataItems.get(position).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(position).getCorrectAnswer());
questionInfo.setScore(dataItems.get(position).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(position).setIsSelect("0");
}
resultA="A";
}
});
holder.layoutB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
mapClick.put(position, true);
if(map.containsKey(position)){
return;
}
if(dataItems.get(position).getCorrectAnswer().contains("B")){
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
isCorrect=ConstantUtil.isCorrect;
if(position==viewItems.size()-1){
answerLast.append("B");
}else{
answer.append("B");
}
}else{
isCorrect=ConstantUtil.isError;
mapMultiSelect.put(position, isCorrect);
errortopicNum+=1;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(position).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(position).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(position).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect("B");
errorQuestionInfo.setAnalysis(dataItems.get(position).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(position).getOption_type());
if(dataItems.get(position).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA().equals("")?"":imgServerUrl+dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB().equals("")?"":imgServerUrl+dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC().equals("")?"":imgServerUrl+dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD().equals("")?"":imgServerUrl+dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE().equals("")?"":imgServerUrl+dataItems.get(position).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
map.put(position, true);
holder.ivB.setImageResource(R.drawable.ic_practice_test_wrong);
holder.tvB.setTextColor(Color.parseColor("#d53235"));
//提示
holder.wrongLayout.setVisibility(View.VISIBLE);
holder.explaindetailTv.setText(""+dataItems.get(position).getAnalysis());
//显示正确选项
if(dataItems.get(position).getCorrectAnswer().contains("A")){
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("B")){
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("C")){
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("D")){
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("E")){
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(position).getQuestionId());
questionInfo.setQuestionType(dataItems.get(position).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(position).getCorrectAnswer());
questionInfo.setScore(dataItems.get(position).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(position).setIsSelect("0");
}
resultB="B";
}
});
holder.layoutC.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
mapClick.put(position, true);
if(map.containsKey(position)){
return;
}
if(dataItems.get(position).getCorrectAnswer().contains("C")){
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
isCorrect=ConstantUtil.isCorrect;
if(position==viewItems.size()-1){
answerLast.append("C");
}else{
answer.append("C");
}
}else{
isCorrect=ConstantUtil.isError;
mapMultiSelect.put(position, isCorrect);
errortopicNum+=1;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(position).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(position).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(position).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect("C");
errorQuestionInfo.setAnalysis(dataItems.get(position).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(position).getOption_type());
if(dataItems.get(position).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA().equals("")?"":imgServerUrl+dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB().equals("")?"":imgServerUrl+dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC().equals("")?"":imgServerUrl+dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD().equals("")?"":imgServerUrl+dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE().equals("")?"":imgServerUrl+dataItems.get(position).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
map.put(position, true);
holder.ivC.setImageResource(R.drawable.ic_practice_test_wrong);
holder.tvC.setTextColor(Color.parseColor("#d53235"));
//提示
holder.wrongLayout.setVisibility(View.VISIBLE);
holder.explaindetailTv.setText(""+dataItems.get(position).getAnalysis());
//显示正确选项
if(dataItems.get(position).getCorrectAnswer().contains("A")){
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("B")){
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("C")){
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("D")){
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("E")){
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(position).getQuestionId());
questionInfo.setQuestionType(dataItems.get(position).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(position).getCorrectAnswer());
questionInfo.setScore(dataItems.get(position).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(position).setIsSelect("0");
}
resultC="C";
}
});
holder.layoutD.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
mapClick.put(position, true);
if(map.containsKey(position)){
return;
}
if(dataItems.get(position).getCorrectAnswer().contains("D")){
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
isCorrect=ConstantUtil.isCorrect;
if(position==viewItems.size()-1){
answerLast.append("D");
}else{
answer.append("D");
}
}else{
isCorrect=ConstantUtil.isError;
mapMultiSelect.put(position, isCorrect);
errortopicNum+=1;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(position).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(position).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(position).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect("D");
errorQuestionInfo.setAnalysis(dataItems.get(position).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(position).getOption_type());
if(dataItems.get(position).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA().equals("")?"":imgServerUrl+dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB().equals("")?"":imgServerUrl+dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC().equals("")?"":imgServerUrl+dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD().equals("")?"":imgServerUrl+dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE().equals("")?"":imgServerUrl+dataItems.get(position).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
map.put(position, true);
holder.ivD.setImageResource(R.drawable.ic_practice_test_wrong);
holder.tvD.setTextColor(Color.parseColor("#d53235"));
//提示
holder.wrongLayout.setVisibility(View.VISIBLE);
holder.explaindetailTv.setText(""+dataItems.get(position).getAnalysis());
//显示正确选项
if(dataItems.get(position).getCorrectAnswer().contains("A")){
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("B")){
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("C")){
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("D")){
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("E")){
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(position).getQuestionId());
questionInfo.setQuestionType(dataItems.get(position).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(position).getCorrectAnswer());
questionInfo.setScore(dataItems.get(position).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(position).setIsSelect("0");
}
resultD="D";
}
});
holder.layoutE.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
mapClick.put(position, true);
if(map.containsKey(position)){
return;
}
if(dataItems.get(position).getCorrectAnswer().contains("E")){
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
isCorrect=ConstantUtil.isCorrect;
if(position==viewItems.size()-1){
answerLast.append("E");
}else{
answer.append("E");
}
}else{
isCorrect=ConstantUtil.isError;
mapMultiSelect.put(position, isCorrect);
errortopicNum+=1;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(position).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(position).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(position).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect("E");
errorQuestionInfo.setAnalysis(dataItems.get(position).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(position).getOption_type());
if(dataItems.get(position).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA().equals("")?"":imgServerUrl+dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB().equals("")?"":imgServerUrl+dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC().equals("")?"":imgServerUrl+dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD().equals("")?"":imgServerUrl+dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE().equals("")?"":imgServerUrl+dataItems.get(position).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
map.put(position, true);
holder.ivE.setImageResource(R.drawable.ic_practice_test_wrong);
holder.tvE.setTextColor(Color.parseColor("#d53235"));
//提示
holder.wrongLayout.setVisibility(View.VISIBLE);
holder.explaindetailTv.setText(""+dataItems.get(position).getAnalysis());
//显示正确选项
if(dataItems.get(position).getCorrectAnswer().contains("A")){
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("B")){
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("C")){
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("D")){
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
}if(dataItems.get(position).getCorrectAnswer().contains("E")){
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(position).getQuestionId());
questionInfo.setQuestionType(dataItems.get(position).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(position).getCorrectAnswer());
questionInfo.setScore(dataItems.get(position).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(position).setIsSelect("0");
}
resultE="E";
}
});
}else{
//判断题
holder.question.setText("(判断题)"+dataItems.get(position).getQuestionName());
holder.layoutA.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(map.containsKey(position)){
return;
}
map.put(position, true);
if(dataItems.get(position).getCorrectAnswer().contains("A")){
mContext.setCurrentView(position+1);
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
isCorrect=ConstantUtil.isCorrect;
}else{
isCorrect=ConstantUtil.isError;
errortopicNum+=1;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(position).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(position).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(position).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect("A");
errorQuestionInfo.setAnalysis(dataItems.get(position).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(position).getOption_type());
if(dataItems.get(position).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA().equals("")?"":imgServerUrl+dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB().equals("")?"":imgServerUrl+dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC().equals("")?"":imgServerUrl+dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD().equals("")?"":imgServerUrl+dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE().equals("")?"":imgServerUrl+dataItems.get(position).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
holder.ivA.setImageResource(R.drawable.ic_practice_test_wrong);
holder.tvA.setTextColor(Color.parseColor("#d53235"));
//提示
holder.wrongLayout.setVisibility(View.VISIBLE);
holder.explaindetailTv.setText(""+dataItems.get(position).getAnalysis());
//显示正确选项
if(dataItems.get(position).getCorrectAnswer().contains("A")){
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("B")){
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("C")){
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("D")){
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("E")){
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
}
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(position).getQuestionId());
questionInfo.setQuestionType(dataItems.get(position).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(position).getCorrectAnswer());
questionInfo.setScore(dataItems.get(position).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(position).setIsSelect("0");
}
});
holder.layoutB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(map.containsKey(position)){
return;
}
map.put(position, true);
if(dataItems.get(position).getCorrectAnswer().contains("B")){
mContext.setCurrentView(position+1);
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
isCorrect=ConstantUtil.isCorrect;
}else{
isCorrect=ConstantUtil.isError;
errortopicNum+=1;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(position).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(position).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(position).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect("B");
errorQuestionInfo.setAnalysis(dataItems.get(position).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(position).getOption_type());
if(dataItems.get(position).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA().equals("")?"":imgServerUrl+dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB().equals("")?"":imgServerUrl+dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC().equals("")?"":imgServerUrl+dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD().equals("")?"":imgServerUrl+dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE().equals("")?"":imgServerUrl+dataItems.get(position).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
holder.ivB.setImageResource(R.drawable.ic_practice_test_wrong);
holder.tvB.setTextColor(Color.parseColor("#d53235"));
//提示
holder.wrongLayout.setVisibility(View.VISIBLE);
holder.explaindetailTv.setText(""+dataItems.get(position).getAnalysis());
//显示正确选项
if(dataItems.get(position).getCorrectAnswer().contains("A")){
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("B")){
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("C")){
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("D")){
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("E")){
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
}
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(position).getQuestionId());
questionInfo.setQuestionType(dataItems.get(position).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(position).getCorrectAnswer());
questionInfo.setScore(dataItems.get(position).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(position).setIsSelect("0");
}
});
holder.layoutC.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(map.containsKey(position)){
return;
}
map.put(position, true);
if(dataItems.get(position).getCorrectAnswer().contains("C")){
mContext.setCurrentView(position+1);
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
isCorrect=ConstantUtil.isCorrect;
}else{
isCorrect=ConstantUtil.isError;
errortopicNum+=1;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(position).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(position).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(position).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect("C");
errorQuestionInfo.setAnalysis(dataItems.get(position).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(position).getOption_type());
if(dataItems.get(position).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA().equals("")?"":imgServerUrl+dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB().equals("")?"":imgServerUrl+dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC().equals("")?"":imgServerUrl+dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD().equals("")?"":imgServerUrl+dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE().equals("")?"":imgServerUrl+dataItems.get(position).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
holder.ivC.setImageResource(R.drawable.ic_practice_test_wrong);
holder.tvC.setTextColor(Color.parseColor("#d53235"));
//提示
holder.wrongLayout.setVisibility(View.VISIBLE);
holder.explaindetailTv.setText(""+dataItems.get(position).getAnalysis());
//显示正确选项
if(dataItems.get(position).getCorrectAnswer().contains("A")){
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("B")){
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("C")){
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("D")){
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("E")){
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
}
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(position).getQuestionId());
questionInfo.setQuestionType(dataItems.get(position).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(position).getCorrectAnswer());
questionInfo.setScore(dataItems.get(position).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(position).setIsSelect("0");
}
});
holder.layoutD.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(map.containsKey(position)){
return;
}
map.put(position, true);
if(dataItems.get(position).getCorrectAnswer().contains("D")){
mContext.setCurrentView(position+1);
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
isCorrect=ConstantUtil.isCorrect;
}else{
isCorrect=ConstantUtil.isError;
errortopicNum+=1;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(position).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(position).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(position).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect("D");
errorQuestionInfo.setAnalysis(dataItems.get(position).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(position).getOption_type());
if(dataItems.get(position).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA().equals("")?"":imgServerUrl+dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB().equals("")?"":imgServerUrl+dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC().equals("")?"":imgServerUrl+dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD().equals("")?"":imgServerUrl+dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE().equals("")?"":imgServerUrl+dataItems.get(position).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
holder.ivD.setImageResource(R.drawable.ic_practice_test_wrong);
holder.tvD.setTextColor(Color.parseColor("#d53235"));
//提示
holder.wrongLayout.setVisibility(View.VISIBLE);
holder.explaindetailTv.setText(""+dataItems.get(position).getAnalysis());
//显示正确选项
if(dataItems.get(position).getCorrectAnswer().contains("A")){
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("B")){
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("C")){
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("D")){
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("E")){
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
}
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(position).getQuestionId());
questionInfo.setQuestionType(dataItems.get(position).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(position).getCorrectAnswer());
questionInfo.setScore(dataItems.get(position).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(position).setIsSelect("0");
}
});
holder.layoutE.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(map.containsKey(position)){
return;
}
map.put(position, true);
if(dataItems.get(position).getCorrectAnswer().contains("E")){
mContext.setCurrentView(position+1);
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
isCorrect=ConstantUtil.isCorrect;
}else{
isCorrect=ConstantUtil.isError;
errortopicNum+=1;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(position).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(position).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(position).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect("E");
errorQuestionInfo.setAnalysis(dataItems.get(position).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(position).getOption_type());
if(dataItems.get(position).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(position).getOptionA().equals("")?"":imgServerUrl+dataItems.get(position).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(position).getOptionB().equals("")?"":imgServerUrl+dataItems.get(position).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(position).getOptionC().equals("")?"":imgServerUrl+dataItems.get(position).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(position).getOptionD().equals("")?"":imgServerUrl+dataItems.get(position).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(position).getOptionE().equals("")?"":imgServerUrl+dataItems.get(position).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
holder.ivE.setImageResource(R.drawable.ic_practice_test_wrong);
holder.tvE.setTextColor(Color.parseColor("#d53235"));
//提示
holder.wrongLayout.setVisibility(View.VISIBLE);
holder.explaindetailTv.setText(""+dataItems.get(position).getAnalysis());
//显示正确选项
if(dataItems.get(position).getCorrectAnswer().contains("A")){
holder.ivA.setImageResource(R.drawable.ic_practice_test_right);
holder.tvA.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("B")){
holder.ivB.setImageResource(R.drawable.ic_practice_test_right);
holder.tvB.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("C")){
holder.ivC.setImageResource(R.drawable.ic_practice_test_right);
holder.tvC.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("D")){
holder.ivD.setImageResource(R.drawable.ic_practice_test_right);
holder.tvD.setTextColor(Color.parseColor("#61bc31"));
}else if(dataItems.get(position).getCorrectAnswer().contains("E")){
holder.ivE.setImageResource(R.drawable.ic_practice_test_right);
holder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
}
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(position).getQuestionId());
questionInfo.setQuestionType(dataItems.get(position).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(position).getCorrectAnswer());
questionInfo.setScore(dataItems.get(position).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(position).setIsSelect("0");
}
});
}
ForegroundColorSpan blueSpan = new ForegroundColorSpan(Color.parseColor("#2b89e9"));
SpannableStringBuilder builder1 = new SpannableStringBuilder(holder.question.getText().toString());
builder1.setSpan(blueSpan, 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.question.setText(builder1);
// 最后一页修改"下一步"按钮文字
if (position == viewItems.size() - 1) {
holder.nextText.setText("提交");
holder.nextImage.setImageResource(R.drawable.vote_submit_finish);
}
holder.previousBtn.setOnClickListener(new LinearOnClickListener(position - 1, false,position,holder));
holder.nextBtn.setOnClickListener(new LinearOnClickListener(position + 1, true,position,holder));
container.addView(viewItems.get(position));
return viewItems.get(position);
}
/**
* @author 设置上一步和下一步按钮监听
*
*/
class LinearOnClickListener implements OnClickListener {
private int mPosition;
private int mPosition1;
private boolean mIsNext;
private ViewHolder viewHolder;
public LinearOnClickListener(int position, boolean mIsNext,int position1,ViewHolder viewHolder) {
mPosition = position;
mPosition1 = position1;
this.viewHolder = viewHolder;
this.mIsNext = mIsNext;
}
@Override
public void onClick(View v) {
if (mPosition == viewItems.size()) {
//单选
if(dataItems.get(mPosition1).getQuestionType().equals("0")){
if(!map.containsKey(mPosition1)){
Toast.makeText(mContext, "请选择选项", Toast.LENGTH_SHORT).show();
return;
}
mContext.uploadExamination(errortopicNum);
}else if(dataItems.get(mPosition1).getQuestionType().equals("1")){
//判断多选时的点击
if(!map.containsKey(mPosition1)){
if(!mapClick.containsKey(mPosition1)){
Toast.makeText(mContext, "请选择选项", Toast.LENGTH_SHORT).show();
return;
}
}
map.put(mPosition1, true);
if(mapMultiSelect.containsKey(mPosition1)){
//提交答题
mContext.uploadExamination(errortopicNum);
}else{
String ssStr=dataItems.get(mPosition1).getCorrectAnswer();
ssStr=ssStr.replace("|", "");
if(mPosition == viewItems.size()){
if(answerLast.toString().contains("A")){
answer1.append("A");
}if(answerLast.toString().contains("B")){
answer1.append("B");
}if(answerLast.toString().contains("C")){
answer1.append("C");
}if(answerLast.toString().contains("D")){
answer1.append("D");
}if(answerLast.toString().contains("E")){
answer1.append("E");
}
}else{
if(answer.toString().contains("A")){
answer1.append("A");
}if(answer.toString().contains("B")){
answer1.append("B");
}if(answer.toString().contains("C")){
answer1.append("C");
}if(answer.toString().contains("D")){
answer1.append("D");
}if(answer.toString().contains("E")){
answer1.append("E");
}
}
if(answer1.toString().equals(ssStr)){
//清除答案
answer.delete(0, answer.length());
answer1.delete(0, answer1.length());
isCorrect=ConstantUtil.isCorrect;
mapMultiSelect.put(mPosition1, ConstantUtil.isCorrect);
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(mPosition1).getQuestionId());
questionInfo.setQuestionType(dataItems.get(mPosition1).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(mPosition1).getCorrectAnswer());
questionInfo.setScore(dataItems.get(mPosition1).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(mPosition1).setIsSelect("0");
//提交答题
mContext.uploadExamination(errortopicNum);
}else{
//清除答案
answer.delete(0, answer.length());
answer1.delete(0, answer1.length());
errortopicNum+=1;
isCorrect=ConstantUtil.isError;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(mPosition1).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(mPosition1).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(mPosition1).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect(answer.toString());
errorQuestionInfo.setAnalysis(dataItems.get(mPosition1).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(mPosition1).getOption_type());
if(dataItems.get(mPosition1).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(mPosition1).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(mPosition1).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(mPosition1).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(mPosition1).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(mPosition1).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(mPosition1).getOptionA().equals("")?"":imgServerUrl+dataItems.get(mPosition1).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(mPosition1).getOptionB().equals("")?"":imgServerUrl+dataItems.get(mPosition1).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(mPosition1).getOptionC().equals("")?"":imgServerUrl+dataItems.get(mPosition1).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(mPosition1).getOptionD().equals("")?"":imgServerUrl+dataItems.get(mPosition1).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(mPosition1).getOptionE().equals("")?"":imgServerUrl+dataItems.get(mPosition1).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
isCorrect=ConstantUtil.isError;
mapMultiSelect.put(mPosition1, ConstantUtil.isError);
//提示
viewHolder.wrongLayout.setVisibility(View.VISIBLE);
viewHolder.explaindetailTv.setText(""+dataItems.get(mPosition1).getAnalysis());
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(mPosition1).getQuestionId());
questionInfo.setQuestionType(dataItems.get(mPosition1).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(mPosition1).getCorrectAnswer());
questionInfo.setScore(dataItems.get(mPosition1).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(mPosition1).setIsSelect("0");
//显示正确选项
if(dataItems.get(mPosition1).getCorrectAnswer().contains("A")){
viewHolder.ivA.setImageResource(R.drawable.ic_practice_test_right);
viewHolder.tvA.setTextColor(Color.parseColor("#61bc31"));
}
if(dataItems.get(mPosition1).getCorrectAnswer().contains("B")){
viewHolder.ivB.setImageResource(R.drawable.ic_practice_test_right);
viewHolder.tvB.setTextColor(Color.parseColor("#61bc31"));
}
if(dataItems.get(mPosition1).getCorrectAnswer().contains("C")){
viewHolder.ivC.setImageResource(R.drawable.ic_practice_test_right);
viewHolder.tvC.setTextColor(Color.parseColor("#61bc31"));
}
if(dataItems.get(mPosition1).getCorrectAnswer().contains("D")){
viewHolder.ivD.setImageResource(R.drawable.ic_practice_test_right);
viewHolder.tvD.setTextColor(Color.parseColor("#61bc31"));
}
if(dataItems.get(mPosition1).getCorrectAnswer().contains("E")){
viewHolder.ivE.setImageResource(R.drawable.ic_practice_test_right);
viewHolder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
}
}
}else{
if(!map.containsKey(mPosition1)){
Toast.makeText(mContext, "请选择选项", Toast.LENGTH_SHORT).show();
return;
}
mContext.uploadExamination(errortopicNum);
}
} else {
if(mPosition ==-1){
Toast.makeText(mContext, "已经是第一页", Toast.LENGTH_SHORT).show();
return;
}else{
//单选
if(dataItems.get(mPosition1).getQuestionType().equals("0")){
if(mIsNext){
if(!map.containsKey(mPosition1)){
Toast.makeText(mContext, "请选择选项", Toast.LENGTH_SHORT).show();
return;
}
}
isNext = mIsNext;
mContext.setCurrentView(mPosition);
}else if(dataItems.get(mPosition1).getQuestionType().equals("1")){
if(mIsNext){
//判断多选时的点击
if(!map.containsKey(mPosition1)){
if(!mapClick.containsKey(mPosition1)){
Toast.makeText(mContext, "请选择选项", Toast.LENGTH_SHORT).show();
return;
}
}
map.put(mPosition1, true);
if(mapMultiSelect.containsKey(mPosition1)){
//清除答案
answer.delete(0, answer.length());
//选过的,直接跳转下一题
isNext = mIsNext;
mContext.setCurrentView(mPosition);
}else{
String ssStr=dataItems.get(mPosition1).getCorrectAnswer();
ssStr=ssStr.replace("|", "");
if(answer.toString().contains("A")){
answer1.append("A");
}if(answer.toString().contains("B")){
answer1.append("B");
}if(answer.toString().contains("C")){
answer1.append("C");
}if(answer.toString().contains("D")){
answer1.append("D");
}if(answer.toString().contains("E")){
answer1.append("E");
}
if(answer1.toString().equals(ssStr)){
//清除答案
answer.delete(0, answer.length());
answer1.delete(0, answer1.length());
isCorrect=ConstantUtil.isCorrect;
mapMultiSelect.put(mPosition1, ConstantUtil.isCorrect);
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(mPosition1).getQuestionId());
questionInfo.setQuestionType(dataItems.get(mPosition1).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(mPosition1).getCorrectAnswer());
questionInfo.setScore(dataItems.get(mPosition1).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(mPosition1).setIsSelect("0");
isNext = mIsNext;
mContext.setCurrentView(mPosition);
}else{
//清除答案
answer.delete(0, answer.length());
answer1.delete(0, answer1.length());
errortopicNum+=1;
isCorrect=ConstantUtil.isError;
//自动添加错误题目
ErrorQuestionInfo errorQuestionInfo=new ErrorQuestionInfo();
errorQuestionInfo.setQuestionName(dataItems.get(mPosition1).getQuestionName());
errorQuestionInfo.setQuestionType(dataItems.get(mPosition1).getQuestionType());
errorQuestionInfo.setQuestionAnswer(dataItems.get(mPosition1).getCorrectAnswer());
errorQuestionInfo.setIsRight(isCorrect);
errorQuestionInfo.setQuestionSelect(answer.toString());
errorQuestionInfo.setAnalysis(dataItems.get(mPosition1).getAnalysis());
errorQuestionInfo.setOptionType(dataItems.get(mPosition1).getOption_type());
if(dataItems.get(mPosition1).getOption_type().equals("0")){
errorQuestionInfo.setOptionA(dataItems.get(mPosition1).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(mPosition1).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(mPosition1).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(mPosition1).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(mPosition1).getOptionE());
}else{
errorQuestionInfo.setOptionA(dataItems.get(mPosition1).getOptionA().equals("")?"":imgServerUrl+dataItems.get(mPosition1).getOptionA());
errorQuestionInfo.setOptionB(dataItems.get(mPosition1).getOptionB().equals("")?"":imgServerUrl+dataItems.get(mPosition1).getOptionB());
errorQuestionInfo.setOptionC(dataItems.get(mPosition1).getOptionC().equals("")?"":imgServerUrl+dataItems.get(mPosition1).getOptionC());
errorQuestionInfo.setOptionD(dataItems.get(mPosition1).getOptionD().equals("")?"":imgServerUrl+dataItems.get(mPosition1).getOptionD());
errorQuestionInfo.setOptionE(dataItems.get(mPosition1).getOptionE().equals("")?"":imgServerUrl+dataItems.get(mPosition1).getOptionE());
}
long colunm=dbManager.insertErrorQuestion(errorQuestionInfo);
if(colunm == -1)
{
Toast.makeText(mContext, "添加错误", Toast.LENGTH_SHORT).show();
}
isCorrect=ConstantUtil.isError;
mapMultiSelect.put(mPosition1, ConstantUtil.isError);
//提示
viewHolder.wrongLayout.setVisibility(View.VISIBLE);
viewHolder.explaindetailTv.setText(""+dataItems.get(mPosition1).getAnalysis());
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(mPosition1).getQuestionId());
questionInfo.setQuestionType(dataItems.get(mPosition1).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(mPosition1).getCorrectAnswer());
questionInfo.setScore(dataItems.get(mPosition1).getScore());
questionInfo.setIs_correct(isCorrect);
mContext.questionInfos.add(questionInfo);
dataItems.get(mPosition1).setIsSelect("0");
//显示正确选项
if(dataItems.get(mPosition1).getCorrectAnswer().contains("A")){
viewHolder.ivA.setImageResource(R.drawable.ic_practice_test_right);
viewHolder.tvA.setTextColor(Color.parseColor("#61bc31"));
}
if(dataItems.get(mPosition1).getCorrectAnswer().contains("B")){
viewHolder.ivB.setImageResource(R.drawable.ic_practice_test_right);
viewHolder.tvB.setTextColor(Color.parseColor("#61bc31"));
}
if(dataItems.get(mPosition1).getCorrectAnswer().contains("C")){
viewHolder.ivC.setImageResource(R.drawable.ic_practice_test_right);
viewHolder.tvC.setTextColor(Color.parseColor("#61bc31"));
}
if(dataItems.get(mPosition1).getCorrectAnswer().contains("D")){
viewHolder.ivD.setImageResource(R.drawable.ic_practice_test_right);
viewHolder.tvD.setTextColor(Color.parseColor("#61bc31"));
}
if(dataItems.get(mPosition1).getCorrectAnswer().contains("E")){
viewHolder.ivE.setImageResource(R.drawable.ic_practice_test_right);
viewHolder.tvE.setTextColor(Color.parseColor("#61bc31"));
}
}
}
}else{
mContext.setCurrentView(mPosition);
}
}else{
if(mIsNext){
if(!map.containsKey(mPosition1)){
Toast.makeText(mContext, "请选择选项", Toast.LENGTH_SHORT).show();
return;
}
}
isNext = mIsNext;
mContext.setCurrentView(mPosition);
}
}
}
}
}
@Override
public int getCount() {
if (viewItems == null)
return 0;
return viewItems.size();
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
//错题数
public int errorTopicNum(){
if(errortopicNum!=0){
return errortopicNum;
}
return 0;
}
public class ViewHolder {
TextView questionType;
TextView question;
LinearLayout previousBtn, nextBtn,errorBtn;
TextView nextText;
TextView totalText;
ImageView nextImage;
LinearLayout wrongLayout;
TextView explaindetailTv;
LinearLayout layoutA;
LinearLayout layoutB;
LinearLayout layoutC;
LinearLayout layoutD;
LinearLayout layoutE;
ImageView ivA;
ImageView ivB;
ImageView ivC;
ImageView ivD;
ImageView ivE;
TextView tvA;
TextView tvB;
TextView tvC;
TextView tvD;
TextView tvE;
ImageView ivA_;
ImageView ivB_;
ImageView ivC_;
ImageView ivD_;
ImageView ivE_;
}
}
适配器写好之后,就要在activity上面调用了。
package com.example.answer;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import com.example.answer.adapter.ExaminationSubmitAdapter;
import com.example.answer.bean.AnSwerInfo;
import com.example.answer.bean.ErrorQuestionInfo;
import com.example.answer.bean.SaveQuestionInfo;
import com.example.answer.database.DBManager;
import com.example.answer.util.ConstantData;
import com.example.answer.util.ConstantUtil;
import com.example.answer.util.ViewPagerScroller;
import com.example.answer.view.VoteSubmitViewPager;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
/**
* 答题
*
*/
public class AnalogyExaminationActivity extends Activity {
private ImageView leftIv;
private TextView titleTv;
private TextView right;
VoteSubmitViewPager viewPager;
ExaminationSubmitAdapter pagerAdapter;
List<View> viewItems = new ArrayList<View>();
List<AnSwerInfo> dataItems = new ArrayList<AnSwerInfo>();
private ProgressDialog progressDialog;
private String pageCode;
private int pageScore;
private int errortopicNums;// 错题数
private int errortopicNums1;// 错题数
private String isPerfectData = "1";// 是否完善资料0完成 1未完成
private String type = "0";// 0模拟 1竞赛
private String errorMsg="";
Dialog builderSubmit;
public List<Map<String, SaveQuestionInfo>> list = new ArrayList<Map<String, SaveQuestionInfo>>();
public Map<String, SaveQuestionInfo> map2 = new HashMap<String, SaveQuestionInfo>();
public List<SaveQuestionInfo> questionInfos = new ArrayList<SaveQuestionInfo>();
Timer timer;
TimerTask timerTask;
int minute = 5;
int second = 0;
boolean isPause = false;
int isFirst;
DBManager dbManager;
String dateStr = "";
String imgServerUrl = "";
private boolean isUpload= false;
private Handler handlerSubmit = new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch (msg.what) {
case 1:
showSubmitDialog();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
builderSubmit.dismiss();
finish();
}
}, 3000);
break;
default:
break;
}
}
};
Handler handlerTime = new Handler() {
public void handleMessage(Message msg) {
// 判断时间快到前2分钟字体颜色改变
if (minute < 2) {
right.setTextColor(Color.RED);
} else {
right.setTextColor(Color.WHITE);
}
if (minute == 0) {
if (second == 0) {
isFirst+=1;
// 时间到
if(isFirst==1){
showTimeOutDialog(true, "0");
}
right.setText("00:00");
if (timer != null) {
timer.cancel();
timer = null;
}
if (timerTask != null) {
timerTask = null;
}
} else {
second--;
if (second >= 10) {
right.setText("0" + minute + ":" + second);
} else {
right.setText("0" + minute + ":0" + second);
}
}
} else {
if (second == 0) {
second = 59;
minute--;
if (minute >= 10) {
right.setText(minute + ":" + second);
} else {
right.setText("0" + minute + ":" + second);
}
} else {
second--;
if (second >= 10) {
if (minute >= 10) {
right.setText(minute + ":" + second);
} else {
right.setText("0" + minute + ":" + second);
}
} else {
if (minute >= 10) {
right.setText(minute + ":0" + second);
} else {
right.setText("0" + minute + ":0" + second);
}
}
}
}
};
};
private Handler handlerStopTime = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
stopTime();
break;
case 1:
startTime();
break;
default:
break;
}
super.handleMessage(msg);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_practice_test);
dbManager = new DBManager(AnalogyExaminationActivity.this);
dbManager.openDB();
initView();
loadData();
ErrorQuestionInfo[] errorQuestionInfos = dbManager.queryAllData();
if (errorQuestionInfos != null) {
// 删除上次保存的我的错题
int colunm = (int) dbManager.deleteAllData();
}
}
public void initView() {
leftIv = (ImageView) findViewById(R.id.left);
titleTv = (TextView) findViewById(R.id.title);
right = (TextView) findViewById(R.id.right);
titleTv.setText("模拟答题");
Drawable drawable1 = getBaseContext().getResources().getDrawable(
R.drawable.ic_practice_time);
drawable1.setBounds(0, 0, drawable1.getMinimumWidth(),
drawable1.getMinimumHeight());
right.setCompoundDrawables(drawable1, null, null, null);
right.setText("15:00");
viewPager = (VoteSubmitViewPager) findViewById(R.id.vote_submit_viewpager);
leftIv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// finish();
isPause = true;
showTimeOutDialog(true, "1");
Message msg = new Message();
msg.what = 0;
handlerStopTime.sendMessage(msg);
}
});
initViewPagerScroll();
}
private void loadData(){
for (int i = 0; i < ConstantData.answerName.length; i++) {
AnSwerInfo info = new AnSwerInfo();
info.setQuestionId(ConstantData.answerId[i]);// 试题主键
info.setQuestionName(ConstantData.answerName[i]);// 试题题目
info.setQuestionType(ConstantData.answerType[i]);// 试题类型0单选1多选
info.setQuestionFor("0");// (0模拟试题,1竞赛试题)
info.setAnalysis(ConstantData.answerAnalysis[i]);// 试题分析
info.setCorrectAnswer(ConstantData.answerCorrect[i]);// 正确答案
info.setOptionA(ConstantData.answerOptionA[i]);// 试题选项A
info.setOptionB(ConstantData.answerOptionB[i]);// 试题选项B
info.setOptionC(ConstantData.answerOptionC[i]);// 试题选项C
info.setOptionD(ConstantData.answerOptionD[i]);// 试题选项D
info.setOptionE(ConstantData.answerOptionE[i]);// 试题选项E
info.setScore(ConstantData.answerScore[i]);// 分值
info.setOption_type("0");
dataItems.add(info);
}
for (int i = 0; i < dataItems.size(); i++) {
viewItems.add(getLayoutInflater().inflate(
R.layout.vote_submit_viewpager_item, null));
}
pagerAdapter = new ExaminationSubmitAdapter(
AnalogyExaminationActivity.this, viewItems,
dataItems,imgServerUrl);
viewPager.setAdapter(pagerAdapter);
viewPager.getParent()
.requestDisallowInterceptTouchEvent(false);
}
/**
* 设置ViewPager的滑动速度
*
* */
private void initViewPagerScroll( ){
try {
Field mScroller = null;
mScroller = ViewPager.class.getDeclaredField("mScroller");
mScroller.setAccessible(true);
ViewPagerScroller scroller = new ViewPagerScroller(viewPager.getContext());
mScroller.set(viewPager, scroller);
}catch(NoSuchFieldException e){
}catch (IllegalArgumentException e){
}catch (IllegalAccessException e){
}
}
/**
* @param index
* 根据索引值切换页面
*/
public void setCurrentView(int index) {
viewPager.setCurrentItem(index);
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
stopTime();
minute = -1;
second = -1;
super.onDestroy();
}
// 提交试卷
public void uploadExamination(int errortopicNum) {
// TODO Auto-generated method stub
String resultlist = "[";
errortopicNums = errortopicNum;
if(questionInfos.size()>0){
//选择过题目
//全部选中
if(questionInfos.size()==dataItems.size()){
for (int i = 0; i < questionInfos.size(); i++) {
if (i == questionInfos.size() - 1) {
resultlist += questionInfos.get(i).toString() + "]";
} else {
resultlist += questionInfos.get(i).toString() + ",";
}
if (questionInfos.size() == 0) {
resultlist += "]";
}
if (questionInfos.get(i).getIs_correct()
.equals(ConstantUtil.isCorrect)) {
int score = Integer.parseInt(questionInfos.get(i).getScore());
pageScore += score;
}
}
}else{
//部分选中
for (int i = 0; i < dataItems.size(); i++) {
if(dataItems.get(i).getIsSelect()==null){
errortopicNums1+=1;
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(i).getQuestionId());
questionInfo.setQuestionType(dataItems.get(i).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(i).getCorrectAnswer());
questionInfo.setScore(dataItems.get(i).getScore());
questionInfo.setIs_correct(ConstantUtil.isError);
questionInfos.add(questionInfo);
}
}
for (int i = 0; i < dataItems.size(); i++){
if (i == dataItems.size() - 1) {
resultlist += questionInfos.get(i).toString() + "]";
} else {
resultlist += questionInfos.get(i).toString() + ",";
}
if (dataItems.size() == 0) {
resultlist += "]";
}
if (questionInfos.get(i).getIs_correct()
.equals(ConstantUtil.isCorrect)) {
int score = Integer.parseInt(questionInfos.get(i).getScore());
pageScore += score;
}
}
}
}else{
//没有选择题目
for (int i = 0; i < dataItems.size(); i++) {
if(dataItems.get(i).getIsSelect()==null){
errortopicNums1+=1;
//保存数据
SaveQuestionInfo questionInfo=new SaveQuestionInfo();
questionInfo.setQuestionId(dataItems.get(i).getQuestionId());
questionInfo.setQuestionType(dataItems.get(i).getQuestionType());
questionInfo.setRealAnswer(dataItems.get(i).getCorrectAnswer());
questionInfo.setScore(dataItems.get(i).getScore());
questionInfo.setIs_correct(ConstantUtil.isError);
questionInfos.add(questionInfo);
}
}
for (int i = 0; i < dataItems.size(); i++){
if (i == dataItems.size() - 1) {
resultlist += questionInfos.get(i).toString() + "]";
} else {
resultlist += questionInfos.get(i).toString() + ",";
}
if (dataItems.size() == 0) {
resultlist += "]";
}
if (questionInfos.get(i).getIs_correct()
.equals(ConstantUtil.isCorrect)) {
int score = Integer.parseInt(questionInfos.get(i).getScore());
pageScore += score;
}
}
}
System.out.println("提交的已经选择的题目数组给后台===="+resultlist);
Message msg = handlerSubmit.obtainMessage();
msg.what = 1;
handlerSubmit.sendMessage(msg);
}
// 弹出对话框通知用户答题时间到
protected void showTimeOutDialog(final boolean flag, final String backtype) {
final Dialog builder = new Dialog(this, R.style.dialog);
builder.setContentView(R.layout.my_dialog);
TextView title = (TextView) builder.findViewById(R.id.dialog_title);
TextView content = (TextView) builder.findViewById(R.id.dialog_content);
if (backtype.equals("0")) {
content.setText("您的答题时间结束,是否提交试卷?");
} else if(backtype.equals("1")){
content.setText("您要结束本次模拟答题吗?");
}else{
content.setText(errorMsg+"");
}
final Button confirm_btn = (Button) builder
.findViewById(R.id.dialog_sure);
Button cancel_btn = (Button) builder.findViewById(R.id.dialog_cancle);
if (backtype.equals("0")) {
confirm_btn.setText("提交");
cancel_btn.setText("退出");
} else if(backtype.equals("1")){
confirm_btn.setText("退出");
cancel_btn.setText("继续答题");
}else{
confirm_btn.setText("确定");
cancel_btn.setVisibility(View.GONE);
}
confirm_btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (backtype.equals("0")){
builder.dismiss();
uploadExamination(pagerAdapter.errorTopicNum());
}else{
builder.dismiss();
finish();
}
}
});
cancel_btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (backtype.equals("0")) {
finish();
builder.dismiss();
} else {
isPause = false;
builder.dismiss();
Message msg = new Message();
msg.what = 1;
handlerStopTime.sendMessage(msg);
}
}
});
builder.setCanceledOnTouchOutside(false);// 设置点击Dialog外部任意区域关闭Dialog
builder.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode,
KeyEvent event) {
return flag;
}
});
builder.show();
}
// 弹出对话框通知用户提交成功
protected void showSubmitDialog() {
builderSubmit = new Dialog(this, R.style.dialog);
builderSubmit.setContentView(R.layout.my_dialog);
TextView title = (TextView) builderSubmit.findViewById(R.id.dialog_title);
TextView content = (TextView) builderSubmit.findViewById(R.id.dialog_content);
content.setText("提交成功,感谢您的参与!");
final Button confirm_btn = (Button) builderSubmit
.findViewById(R.id.dialog_sure);
confirm_btn.setVisibility(View.VISIBLE);
Button cancel_btn = (Button) builderSubmit.findViewById(R.id.dialog_cancle);
cancel_btn.setVisibility(View.VISIBLE);
builderSubmit.setCanceledOnTouchOutside(false);// 设置点击Dialog外部任意区域关闭Dialog
builderSubmit.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
return true;
}
});
builderSubmit.show();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
isPause = true;
showTimeOutDialog(true, "1");
Message msg = new Message();
msg.what = 0;
handlerStopTime.sendMessage(msg);
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
Message msg = new Message();
msg.what = 0;
handlerStopTime.sendMessage(msg);
super.onPause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
Message msg = new Message();
msg.what = 1;
handlerStopTime.sendMessage(msg);
super.onResume();
}
private void startTime() {
if (timer == null) {
timer = new Timer();
}
if (timerTask == null) {
timerTask = new TimerTask() {
@Override
public void run() {
Message msg = new Message();
msg.what = 0;
handlerTime.sendMessage(msg);
}
};
}
if (timer != null && timerTask != null) {
timer.schedule(timerTask, 0, 1000);
}
}
private void stopTime(){
if(timer!=null){
timer.cancel();
timer=null;
}
if(timerTask!=null){
timerTask.cancel();
timerTask=null;
}
}
}
这样就可以实现考试了,当然还有好多地方需要优化的(后期经升级了),需要源码的可以**
源码地址:https://github.com/twjitm/Answer
上不了git的同学可以在这下载
更多推荐
已为社区贡献2条内容
所有评论(0)