最近没事做一点开发练练手吧,复习一下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>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
- 345
- 346
- 347
- 348
- 349
- 350
- 351
- 352
- 353
- 354
- 355
- 356
- 357
- 358
- 359
- 360
- 361
- 362
- 363
- 364
- 365
- 366
- 367
- 368
- 369
- 370
- 371
- 372
- 373
- 374
- 375
- 376
- 377
- 378
- 379
- 380
布局又了,就要写适配器了,适配器里面有各种逻辑判断,
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());再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow