本项目是用eclipse软件编写,经过我的亲自实践,其真实有效,希望能给您有所帮助 项目版本:android5.1.1 AVD建议:android4.4.2及以上 若有不足之处或不对的地方,欢迎大佬们指点 |
习题详情界面主要用于展示每章的所有选择题,每道题由题干、A选项、B选项、 C选项、D选项组成,当用户选择某个选项后程序会自行判断对错,显示正确答案(用户选择答案后不能重新进行选择)
将习题详情界面所需图片exercises_a.png
, exercises_b.png
、
exercises_c.png
、exercises_d.png
、exercises _error_icon.png
、 exercises right icon.png
导入 drawable
文件夹中。
activity_exercises_detail.xml
res/layout
文件夹中新建activity_exercises_detail.xml
文件,代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical" >
<include layout="@layout/main_title_bar" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:text="@string/T_xuan"
android:textColor="#000000"
android:textSize="16sp"
android:textStyle="bold"
android:visibility="gone" />
<ListView
android:id="@+id/lv_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@null" />
LinearLayout>
在values文件夹下的string.xml
文件里面输入文本信息:
<string name="T_xuan">一 、选择题string>
每一个Item包含题干部分和四个选项,每个选项包含选项图片和选项内容
在res/layout
文件夹中,创建一个布局文件exercises_detail_list_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/white"
android:padding="15dp">
<TextView
android:id="@+id/tv_subject"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="1.5"
android:textColor="#000000"
android:textSize="14sp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_a"
android:layout_width="35dp"
android:layout_height="35dp"
android:contentDescription="@null"
android:src="@drawable/exercises_a" />
<TextView
android:id="@+id/tv_a"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:lineSpacingMultiplier="1.5"
android:textColor="#000000"
android:textSize="12sp" />
LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_b"
android:layout_width="35dp"
android:layout_height="35dp"
android:contentDescription="@null"
android:src="@drawable/exercises_b" />
<TextView
android:id="@+id/tv_b"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:lineSpacingMultiplier="1.5"
android:textColor="#000000"
android:textSize="12sp" />
LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_c"
android:layout_width="35dp"
android:layout_height="35dp"
android:contentDescription="@null"
android:src="@drawable/exercises_c" />
<TextView
android:id="@+id/tv_c"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:lineSpacingMultiplier="1.5"
android:textColor="#000000"
android:textSize="12sp" />
LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_d"
android:layout_width="35dp"
android:layout_height="35dp"
android:contentDescription="@null"
android:src="@drawable/exercises_d" />
<TextView
android:id="@+id/tv_d"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:lineSpacingMultiplier="1.5"
android:textColor="#000000"
android:textSize="12sp" />
LinearLayout>
LinearLayout>
在assets
文件夹中创建10个XML
文件保存每章的习题内容。每个XML
文件都包含习题 的Id、题干、选项内容及正确答案等信息。(没有assets
就新建一个)
选中assets
文件夹,然后右击并选择【File】选项,创建一个XML文件,命名 为chapter1.xml
,依此类推创建其余9个XML文件
chapter1.xml
代码如下:(其余九个我会在文章最后面贴出来,原本计划贴在评论处的,奈何评论填不了这么多字)
<infos>
<exercises id="1">
<subject>1.Android安装包文件简称APK,其后缀名是()。subject>
<a>.exea>
<b>.txtb>
<c>.apkc>
<d>.appd>
<answer>3answer>
exercises>
<exercises id="2">
<subject>2.下列选项中不属于ADT Bundle的是()。subject>
<a>Eclipsea>
<b>SDKb>
<c>SDK Manager.exec>
<d>JDKd>
<answer>4answer>
exercises>
<exercises id="3">
<subject>3.应用程序层是一个核心应用程序的集合,主要包括()。subject>
<a>活动管理器a>
<b>短信程序b>
<c>音频驱动c>
<d>Dalvik 虚拟机d>
<answer>2answer>
exercises>
<exercises id="4">
<subject>4.ADB 的常见指令中”列出所有设备“的指令是()。subject>
<a>adb uninstalla>
<b>adb installb>
<c>adb devicec>
<d>adb emulator-avdd>
<answer>3answer>
exercises>
<exercises id="5">
<subject>5.创建程序时,填写的Application Name表示()。subject>
<a>应用名称a>
<b>项目名称b>
<c>项目的包名c>
<d>类的名字d>
<answer>1answer>
exercises>
infos>
在AnalysisUtils.java
文件里添加一个XML数据解析方法getExercisesInfos()
,使用Pull
解析方式对数据进行解析,具体代码如下:
/**
*解析每章的习题
*/
public static List<ExercisesBean> getExercisesInfos(InputStream is) throws Exception {
XmlPullParser parser= Xml.newPullParser();
parser.setInput(is, "utf-8");
List<ExercisesBean> exercisesInfos=null;
ExercisesBean exercisesInfo=null;
int type=parser.getEventType();
while (type!=XmlPullParser.END_DOCUMENT) {
switch (type) {
case XmlPullParser.START_TAG:
if("infos".equals(parser.getName())){
exercisesInfos=new ArrayList<ExercisesBean>();
}else if("exercises".equals(parser.getName())){
exercisesInfo=new ExercisesBean();
String ids=parser.getAttributeValue(0);
exercisesInfo.subjectId=Integer.parseInt(ids);
}else if("subject".equals(parser.getName())){
String subject=parser.nextText();
exercisesInfo.subject=subject;
}else if("a".equals(parser.getName())){
String a=parser.nextText();
exercisesInfo.a=a;
}else if("b".equals(parser.getName())){
String b=parser.nextText();
exercisesInfo.b=b;
}else if("c".equals(parser.getName())){
String c=parser.nextText();
exercisesInfo.c=c;
}else if("d".equals(parser.getName())){
String d=parser.nextText();
exercisesInfo.d=d;
}else if("answer".equals(parser.getName())){
String answer=parser.nextText();
exercisesInfo.answer=Integer.parseInt(answer);
}
break;
case XmlPullParser.END_TAG:
if("exercises".equals(parser.getName())){
exercisesInfos.add(exercisesInfo);
exercisesInfo=null;
}
break;
}
type=parser.next();
}
return exercisesInfos;
}
/**
* 设置A、B、C、D选项是否可点击
* 在习题详情界面用户点击某一道题的选项之后会自动提示正确答案,并且做过的题不能重做
*/
public static void setABCDEnable(boolean value,ImageView iv_a,ImageView iv_b,ImageView iv_c,ImageView iv_d){
iv_a.setEnabled(value);
iv_b.setEnabled(value);
iv_c.setEnabled(value);
iv_d.setEnabled(value);
}
创建一个数据适配器来对ListView
进行数据填充。由于做过的习题不允许用户重做,因此用ArrayList
来记录做过的习题位置。
在china.ynyx.heyunhui.adapter
包中创建一个 ExercisesDetailAdapter
类继承 BaseAdapter
类
具体代码如下:ExercisesDetailAdapter.java
package china.ynyx.heyunhui.adapter;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import china.ynyx.heyunhui.R;
import china.ynyx.heyunhui.bean.ExercisesBean;
import china.ynyx.heyunhui.utils.AnalysisUtils;
public class ExercisesDetailAdapter extends BaseAdapter {
private Context mContext;
private List<ExercisesBean> ebl;
private OnSelectListener onSelectListener;
public ExercisesDetailAdapter(Context context,
OnSelectListener onSelectListener) {
this.mContext = context;
this.onSelectListener = onSelectListener;
}
public void setData(List<ExercisesBean> ebl) {
this.ebl = ebl;
notifyDataSetChanged();
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return ebl == null ? 0 : ebl.size();
}
@Override
public ExercisesBean getItem(int position) {
// TODO Auto-generated method stub
return ebl == null ? null : ebl.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
private ArrayList<String> selectedPosition = new ArrayList<String>();//记录点击的位置
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder vh;
if (convertView == null) {
vh = new ViewHolder();
convertView = LayoutInflater.from(mContext).inflate(
R.layout.exercises_detail_list_item, null);
vh.subject = (TextView) convertView.findViewById(R.id.tv_subject);
vh.tv_a = (TextView) convertView.findViewById(R.id.tv_a);
vh.tv_b = (TextView) convertView.findViewById(R.id.tv_b);
vh.tv_c = (TextView) convertView.findViewById(R.id.tv_c);
vh.tv_d = (TextView) convertView.findViewById(R.id.tv_d);
vh.iv_a = (ImageView) convertView.findViewById(R.id.iv_a);
vh.iv_b = (ImageView) convertView.findViewById(R.id.iv_b);
vh.iv_c = (ImageView) convertView.findViewById(R.id.iv_c);
vh.iv_d = (ImageView) convertView.findViewById(R.id.iv_d);
convertView.setTag(vh);
} else {
vh = (ViewHolder) convertView.getTag();
}
final ExercisesBean bean = getItem(position);
if (bean != null) {
vh.subject.setText(bean.subject);
vh.tv_a.setText(bean.a);
vh.tv_b.setText(bean.b);
vh.tv_c.setText(bean.c);
vh.tv_d.setText(bean.d);
}
if (!selectedPosition.contains("" + position)) {
vh.iv_a.setImageResource(R.drawable.exercises_a);
vh.iv_b.setImageResource(R.drawable.exercises_b);
vh.iv_c.setImageResource(R.drawable.exercises_c);
vh.iv_d.setImageResource(R.drawable.exercises_d);
AnalysisUtils.setABCDEnable(true, vh.iv_a, vh.iv_b, vh.iv_c, vh.iv_d);
} else {
AnalysisUtils.setABCDEnable(false, vh.iv_a, vh.iv_b, vh.iv_c, vh.iv_d);
switch (bean.select) {
case 0:
/**
* 用户所选项是正确的
* 当用户选择的答案是正 确答案时,需要将相应的选项图标设为绿色。
*/
if (bean.answer == 1) {
vh.iv_a.setImageResource(R.drawable.exercises_right_icon);
vh.iv_b.setImageResource(R.drawable.exercises_b);
vh.iv_c.setImageResource(R.drawable.exercises_c);
vh.iv_d.setImageResource(R.drawable.exercises_d);
} else if (bean.answer == 2) {
vh.iv_a.setImageResource(R.drawable.exercises_a);
vh.iv_b.setImageResource(R.drawable.exercises_right_icon);
vh.iv_c.setImageResource(R.drawable.exercises_c);
vh.iv_d.setImageResource(R.drawable.exercises_d);
} else if (bean.answer == 3) {
vh.iv_a.setImageResource(R.drawable.exercises_a);
vh.iv_b.setImageResource(R.drawable.exercises_b);
vh.iv_c.setImageResource(R.drawable.exercises_right_icon);
vh.iv_d.setImageResource(R.drawable.exercises_d);
} else if (bean.answer == 4) {
vh.iv_a.setImageResource(R.drawable.exercises_a);
vh.iv_b.setImageResource(R.drawable.exercises_b);
vh.iv_c.setImageResource(R.drawable.exercises_c);
vh.iv_d.setImageResource(R.drawable.exercises_right_icon);
}
break;
case 1:
/**
* 用户所选项A是错误的
* 当用户选择A选 项之后首先将A选项之前的图标设为红色,之后将正确选项的图标设为绿色
*/
vh.iv_a.setImageResource(R.drawable.exercises_error_icon);
if (bean.answer == 2) {
vh.iv_b.setImageResource(R.drawable.exercises_right_icon);
vh.iv_c.setImageResource(R.drawable.exercises_c);
vh.iv_d.setImageResource(R.drawable.exercises_d);
} else if (bean.answer == 3) {
vh.iv_b.setImageResource(R.drawable.exercises_b);
vh.iv_c.setImageResource(R.drawable.exercises_right_icon);
vh.iv_d.setImageResource(R.drawable.exercises_d);
} else if (bean.answer== 4) {
vh.iv_b.setImageResource(R.drawable.exercises_b);
vh.iv_c.setImageResource(R.drawable.exercises_c);
vh.iv_d.setImageResource(R.drawable.exercises_right_icon);
}
break;
case 2:
/**
* 用户所选项B是错误的
* 当用户选择B选 项之后首先将B选项之前的图标设为红色,之后将正确选项的图标设为绿色
*/
vh.iv_b.setImageResource(R.drawable.exercises_error_icon);
if (bean.answer == 1) {
vh.iv_a.setImageResource(R.drawable.exercises_right_icon);
vh.iv_c.setImageResource(R.drawable.exercises_c);
vh.iv_d.setImageResource(R.drawable.exercises_d);
} else if (bean.answer == 3) {
vh.iv_a.setImageResource(R.drawable.exercises_a);
vh.iv_c.setImageResource(R.drawable.exercises_right_icon);
vh.iv_d.setImageResource(R.drawable.exercises_d);
} else if (bean.answer == 4) {
vh.iv_a.setImageResource(R.drawable.exercises_a);
vh.iv_c.setImageResource(R.drawable.exercises_c);
vh.iv_d.setImageResource(R.drawable.exercises_right_icon);
}
break;
case 3:
/**
* 用户所选项C是错误的
* 当用户选择C选 项之后首先将B选项之前的图标设为红色,之后将正确选项的图标设为绿色
*/
vh.iv_c.setImageResource(R.drawable.exercises_error_icon);
if (bean.answer == 1) {
vh.iv_a.setImageResource(R.drawable.exercises_right_icon);
vh.iv_b.setImageResource(R.drawable.exercises_b);
vh.iv_d.setImageResource(R.drawable.exercises_d);
} else if (bean.answer == 2) {
vh.iv_a.setImageResource(R.drawable.exercises_a);
vh.iv_b.setImageResource(R.drawable.exercises_right_icon);
vh.iv_d.setImageResource(R.drawable.exercises_d);
} else if (bean.answer == 4) {
vh.iv_a.setImageResource(R.drawable.exercises_a);
vh.iv_b.setImageResource(R.drawable.exercises_b);
vh.iv_d.setImageResource(R.drawable.exercises_right_icon);
}
break;
case 4:
/**
* 用户所选项D是错误的
* 当用户选择D选 项之后首先将B选项之前的图标设为红色,之后将正确选项的图标设为绿色
*/
vh.iv_d.setImageResource(R.drawable.exercises_error_icon);
if (bean.answer == 1) {
vh.iv_a.setImageResource(R.drawable.exercises_right_icon);
vh.iv_b.setImageResource(R.drawable.exercises_b);
vh.iv_c.setImageResource(R.drawable.exercises_c);
} else if (bean.answer == 2) {
vh.iv_a.setImageResource(R.drawable.exercises_a);
vh.iv_b.setImageResource(R.drawable.exercises_right_icon);
vh.iv_c.setImageResource(R.drawable.exercises_c);
} else if (bean.answer == 3) {
vh.iv_a.setImageResource(R.drawable.exercises_a);
vh.iv_b.setImageResource(R.drawable.exercises_b);
vh.iv_c.setImageResource(R.drawable.exercises_right_icon);
}
break;
default:
break;
}
}
//当用户点击A选项的点击事件
vh.iv_a.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//判断selectedPosition中是否包含此时点击的positon
if (selectedPosition.contains("" + position)) {
selectedPosition.remove("" + position);
} else {
selectedPosition.add(position + "");
}
onSelectListener.onSelectA(position, vh.iv_a, vh.iv_b, vh.iv_c,
vh.iv_d);
}
});
//当用户点击B选项的点击事件
vh.iv_b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (selectedPosition.contains("" + position)) {
selectedPosition.remove("" + position);
} else {
selectedPosition.add(position + "");
}
onSelectListener.onSelectB(position, vh.iv_a, vh.iv_b, vh.iv_c,
vh.iv_d);
}
});
//当用户点击C选项的点击事件
vh.iv_c.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (selectedPosition.contains("" + position)) {
selectedPosition.remove("" + position);
} else {
selectedPosition.add(position + "");
}
onSelectListener.onSelectC(position, vh.iv_a, vh.iv_b, vh.iv_c,
vh.iv_d);
}
});
//当用户点击D选项的点击事件
vh.iv_d.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (selectedPosition.contains("" + position)) {
selectedPosition.remove("" + position);
} else {
selectedPosition.add(position + "");
}
onSelectListener.onSelectD(position, vh.iv_a, vh.iv_b, vh.iv_c,
vh.iv_d);
}
});
return convertView;
}
class ViewHolder {
public TextView subject, tv_a, tv_b, tv_c, tv_d;
public ImageView iv_a, iv_b, iv_c, iv_d;
}
public interface OnSelectListener {
void onSelectA(int position, ImageView iv_a, ImageView iv_b,
ImageView iv_c, ImageView iv_d);
void onSelectB(int position, ImageView iv_a, ImageView iv_b,
ImageView iv_c, ImageView iv_d);
void onSelectC(int position, ImageView iv_a, ImageView iv_b,
ImageView iv_c, ImageView iv_d);
void onSelectD(int position, ImageView iv_a, ImageView iv_b,
ImageView iv_c, ImageView iv_d);
}
}
在习题列表界面中,点击任意一个条目就会跳转到习题详情界面并显示对应章的习 题,在这个跳转的过程中,需要从习题界面获取传递过来的章节Id和Title
在china.ynyx.heyunhui.activity
包中创建一个 ExercisesDetailActivity
类继承 Activity
类
具体代码如下:ExercisesDetailActivity.java
package china.ynyx.heyunhui.activity;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import android.support.v7.app.AppCompatActivity;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import china.ynyx.heyunhui.R;
import china.ynyx.heyunhui.adapter.ExercisesDetailAdapter;
import china.ynyx.heyunhui.bean.ExercisesBean;
import china.ynyx.heyunhui.utils.AnalysisUtils;
public class ExercisesDetailActivity extends AppCompatActivity {
private TextView tv_main_title;
private TextView tv_back;
private RelativeLayout rl_title_bar;
private ListView lv_list;
private String title;
private int id;
private List<ExercisesBean> ebl;
private ExercisesDetailAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_exercises_detail);
//设置此界面为竖屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// 获取从习题界面传递过来的章节id
id = getIntent().getIntExtra("id", 0);
// 获取从习题界面传递过来的章节标题
title = getIntent().getStringExtra("title");
ebl = new ArrayList<ExercisesBean>();
initData();
init();
}
private void initData() {
try {
// 从xml文件中获取习题数据
InputStream is = getResources().getAssets().open(
"chapter" + id + ".xml");
ebl = AnalysisUtils.getExercisesInfos(is);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 初始化控件
*/
private void init() {
tv_main_title = (TextView) findViewById(R.id.tv_main_title);
tv_back = (TextView) findViewById(R.id.tv_back);
rl_title_bar = (RelativeLayout) findViewById(R.id.title_bar);
rl_title_bar.setBackgroundColor(Color.parseColor("#30B4FF"));
lv_list = (ListView) findViewById(R.id.lv_list);
TextView tv = new TextView(this);
tv.setTextColor(Color.parseColor("#000000"));
tv.setTextSize(16.0f);
tv.setText("一、选择题");
tv.setPadding(10, 15, 0, 0);
lv_list.addHeaderView(tv);
tv_main_title.setText(title);
tv_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ExercisesDetailActivity.this.finish();
}
});
adapter = new ExercisesDetailAdapter(ExercisesDetailActivity.this,
new ExercisesDetailAdapter.OnSelectListener() {
@Override
public void onSelectD(int position, ImageView iv_a,
ImageView iv_b, ImageView iv_c, ImageView iv_d) {
//判断如果答案不是4即D选项
if (ebl.get(position).answer != 4) {
ebl.get(position).select=4;
} else {
ebl.get(position).select=0;
}
switch (ebl.get(position).answer) {
case 1:
iv_a.setImageResource(R.drawable.exercises_right_icon);
iv_d.setImageResource(R.drawable.exercises_error_icon);
break;
case 2:
iv_d.setImageResource(R.drawable.exercises_error_icon);
iv_b.setImageResource(R.drawable.exercises_right_icon);
break;
case 3:
iv_d.setImageResource(R.drawable.exercises_error_icon);
iv_c.setImageResource(R.drawable.exercises_right_icon);
break;
case 4:
iv_d.setImageResource(R.drawable.exercises_right_icon);
break;
}
AnalysisUtils.setABCDEnable(false, iv_a, iv_b, iv_c, iv_d);
}
@Override
public void onSelectC(int position, ImageView iv_a,
ImageView iv_b, ImageView iv_c, ImageView iv_d) {
//判断如果答案不是3即C选项
if (ebl.get(position).answer != 3) {
ebl.get(position).select=3;
} else {
ebl.get(position).select=0;
}
switch (ebl.get(position).answer) {
case 1:
iv_a.setImageResource(R.drawable.exercises_right_icon);
iv_c.setImageResource(R.drawable.exercises_error_icon);
break;
case 2:
iv_b.setImageResource(R.drawable.exercises_right_icon);
iv_c.setImageResource(R.drawable.exercises_error_icon);
break;
case 3:
iv_c.setImageResource(R.drawable.exercises_right_icon);
break;
case 4:
iv_c.setImageResource(R.drawable.exercises_error_icon);
iv_d.setImageResource(R.drawable.exercises_right_icon);
break;
}
AnalysisUtils.setABCDEnable(false, iv_a, iv_b, iv_c, iv_d);
}
@Override
public void onSelectB(int position, ImageView iv_a,
ImageView iv_b, ImageView iv_c, ImageView iv_d) {
//判断如果答案不是2即B选项
if (ebl.get(position).answer != 2) {
ebl.get(position).select=2;
} else {
ebl.get(position).select=0;
}
switch (ebl.get(position).answer) {
case 1:
iv_a.setImageResource(R.drawable.exercises_right_icon);
iv_b.setImageResource(R.drawable.exercises_error_icon);
break;
case 2:
iv_b.setImageResource(R.drawable.exercises_right_icon);
break;
case 3:
iv_b.setImageResource(R.drawable.exercises_error_icon);
iv_c.setImageResource(R.drawable.exercises_right_icon);
break;
case 4:
iv_b.setImageResource(R.drawable.exercises_error_icon);
iv_d.setImageResource(R.drawable.exercises_right_icon);
break;
}
AnalysisUtils.setABCDEnable(false, iv_a, iv_b, iv_c, iv_d);
}
@Override
public void onSelectA(int position, ImageView iv_a,
ImageView iv_b, ImageView iv_c, ImageView iv_d) {
//判断如果答案不是1即A选项
if (ebl.get(position).answer != 1) {
ebl.get(position).select=1;
} else {
ebl.get(position).select=0;
}
switch (ebl.get(position).answer) {
case 1:
iv_a.setImageResource(R.drawable.exercises_right_icon);
break;
case 2:
iv_a.setImageResource(R.drawable.exercises_error_icon);
iv_b.setImageResource(R.drawable.exercises_right_icon);
break;
case 3:
iv_a.setImageResource(R.drawable.exercises_error_icon);
iv_c.setImageResource(R.drawable.exercises_right_icon);
break;
case 4:
iv_a.setImageResource(R.drawable.exercises_error_icon);
iv_d.setImageResource(R.drawable.exercises_right_icon);
break;
}
AnalysisUtils.setABCDEnable(false, iv_a, iv_b, iv_c, iv_d);
}
});
adapter.setData(ebl);
lv_list.setAdapter(adapter);
}
}
由于习题详情界面是通过习题界面数据适配器跳转的,因此需要找到ExercisesAdapter.java
文件中的getView()
方法,在注释“//跳转到习题详情界面
”下方添加如下代码:
Intent intent = new Intent(mContext,
ExercisesDetailActivity.class);
//把章节Id传递到习题详情页面
intent.putExtra("id", bean.id);
//把标题传递到习题详情页面
intent.putExtra("title", bean.title);
mContext.startActivity(intent);
AndroidManifest.xml
清单文件最后的最后,别忘了在AndroidManifest.xml
清单文件中注册:
<activity android:name="china.ynyx.heyunhui.activity.ExercisesDetailActivity"></activity>
chapter2.xml
<infos>
<exercises id="1">
<subject>1.以下属性中,哪个属性可以“在指定控件左边”是()。subject>
<a>android:layout_alignLefta>
<b>android:layout_alignParentLeftb>
<c>android:layout_Leftc>
<d>android:layout_toLeftOfd>
<answer>4answer>
exercises>
<exercises id="2">
<subject>2.表格布局中android:layout_column属性的作用是指定()。subject>
<a>行数a>
<b>列数b>
<c>总行数c>
<d>总列数d>
<answer>4answer>
exercises>
<exercises id="3">
<subject>3.实际开发中刮刮乐游戏的布局是按照()布局写的。subject>
<a>相对布局a>
<b>线性布局b>
<c>帧布局c>
<d>绝对布局d>
<answer>3answer>
exercises>
<exercises id="4">
<subject>4.网格布局是Android()新增的布局。subject>
<a>3.0a>
<b>3.1b>
<c>3.2c>
<d>4.0d>
<answer>4answer>
exercises>
<exercises id="5">
<subject>5.相对布局中,“是否跟父布局对齐”是属性()。subject>
<a>android:layout_alignBottoma>
<b>android:layout_alignParentBottomb>
<c>android:layout_alignBaselinec>
<d>android:layout_belowd>
<answer>3answer>
exercises>
infos>
chapter3.xml
<infos>
<exercises id="1">
<subject>1.一个应用程序默认会包含()个Activity。subject>
<a>1个a>
<b>5个b>
<c>10个c>
<d>若干个d>
<answer>1answer>
exercises>
<exercises id="2">
<subject>2.下列方法中,Activity从启动到关闭不会执行的是()。subject>
<a>onCreate()a>
<b>onStart()b>
<c>onResume()c>
<d>onRestart()d>
<answer>4answer>
exercises>
<exercises id="3">
<subject>3.下列组件中,不能使用Intent启动的是()。subject>
<a>Activitya>
<b>启动服务b>
<c>广播c>
<d>内容提供者d>
<answer>4answer>
exercises>
<exercises id="4">
<subject>4.startActivityForResult()方法接收两个参数,第一个是Intent,第二个是()。subject>
<a>resultCodea>
<b>requestCodeb>
<c>请求码c>
<d>datad>
<answer>3answer>
exercises>
<exercises id="5">
<subject>5.下列关于Activity的描述,错误的是()。subject>
<a>Activity是Android四大组件之一a>
<b>Activity有四种启动模式b>
<c>Activity通常用于开启一个广播事件c>
<d>Activity就像一个界面管理员,用户在界面上的操作是通过Activity来管理d>
<answer>3answer>
exercises>
infos>
chapter4.xml
<infos>
<exercises id="1">
<subject>1.下列文件操作权限中,指定文件内容可以追加的是()。subject>
<a>MODE_PRIVATEa>
<b>MODE_WORLD_READABLEb>
<c>MODE_APPENDc>
<d>MODE_WORLD_WRITEABLEd>
<answer>3answer>
exercises>
<exercises id="2">
<subject>2.下列代码中,用于获取SD卡路径的是()。subject>
<a>Environment.getSD();a>
<b>Environment.getExternalStorageState();b>
<c>Environment.getSD Directory();c>
<d>Environment.getExternalStorageDirectory();d>
<answer>4answer>
exercises>
<exercises id="3">
<subject>3.下列选项中,关于文件存储数据的说法错误的是()。subject>
<a>文件存储是以流的形式来操作数据的a>
<b>文件存储可以讲数据存储到SD卡中b>
<c>文件存储可以讲数据存储到内存中c>
<d>Android中只能使用文件存储数据d>
<answer>4answer>
exercises>
<exercises id="4">
<subject>4.下列选项中,关于XML序列化和解析描述合理的是()。subject>
<a>DOM解析会将XML文件的所有内容以文档树方式存放在内存中a>
<b>在序列化对象时,需要使用XmlSerialize序列化器,即XmlSerializer类b>
<c>XmlSerializer类的startDocument()方法用于写入序列号的开始节点c>
<d>XmlSerializer类的startTag()方法用于设置文件的编码方式d>
<answer>2answer>
exercises>
<exercises id="5">
<subject>5.如果要将程序中的私有数据分享给其他应用程序,可以使用的是()。subject>
<a>文件存储a>
<b>SharedPreferencesb>
<c>ContentProviderc>
<d>SQLited>
<answer>3answer>
exercises>
infos>
chapter5.xml
<infos>
<exercises id="1">
<subject>1.使用SQLite数据库进行查询后,必须要做的操作是()。subject>
<a>关闭数据库a>
<b>直接退出b>
<c>关闭Cursorc>
<d>AC都是d>
<answer>4answer>
exercises>
<exercises id="2">
<subject>2.使用SQLiteOpenHelper类可以生成一个数据库并可以对数据库版本进行管理的方法()。subject>
<a>getDatabase()a>
<b>getWriteableDatabase()b>
<c>getWriteable()c>
<d>getAbleDatabase()d>
<answer>2answer>
exercises>
<exercises id="3">
<subject>3.下列命令中,属于SQLite下的命令是()。subject>
<a>shella>
<b>pushb>
<c>quitc>
<d>keytoold>
<answer>2answer>
exercises>
<exercises id="4">
<subject>4.下列关于ListView使用的描述中,不正确的是()。subject>
<a>要使用ListView,必须为该ListView使用Adapter方式传递数据a>
<b>要使用ListView,该布局文件对应的Activity必须继承ListActivityb>
<c>ListView中每一项的视图布局既可以使用内置的布局,也可以使用自定义的布局方式c>
<d>ListView中每一项被选中时,将会出发ListView对象的ItemClick事件d>
<answer>3answer>
exercises>
<exercises id="5">
<subject>5.关于适配的说法正确的是()。subject>
<a>它主要用来存储数据a>
<b>它主要用来把数据绑定在组件上b>
<c>它主要用来存储XML数据c>
<d>它主要用来解析数据d>
<answer>2answer>
exercises>
infos>
chapter6.xml
<infos>
<exercises id="1">
<subject>1.下列选项中,属于Android中四大组件的是()。subject>
<a>Activitya>
<b>ContentReceiverb>
<c>Servicec>
<d>ABC都是d>
<answer>4answer>
exercises>
<exercises id="2">
<subject>2.下列关于ContentResolver的描述,错误的是()。subject>
<a>可以操作数据库数据a>
<b>操作其他应用数据必须知道包名b>
<c>只能操作ContentProvider暴漏的数据c>
<d>可以操作ContentProvider的任意数据d>
<answer>3answer>
exercises>
<exercises id="3">
<subject>3.下列关于内容提供者的描述,不正确的是()。subject>
<a>提供的 Uri必须符合规范a>
<b>可以提供本应用所有数据供别人访问b>
<c>必须在清单文件中注册c>
<d>authorities属性必须和包名一致d>
<answer>2answer>
exercises>
<exercises id="4">
<subject>4.继承ContentProvider类不需要重写的方法是()。subject>
<a>delete()a>
<b>insert()b>
<c>onStart()c>
<d>onUpdate()d>
<answer>3answer>
exercises>
<exercises id="5">
<subject>5.下列关于内容观察者的说法,正确的是()。subject>
<a>可以观察任何数据a>
<b>观察其他应用数据需要权限b>
<c>只能观察到指定Uri的数据c>
<d>观察其他应用数据必须在清单文件中注册d>
<answer>3answer>
exercises>
infos>
chapter7.xml
<infos>
<exercises id="1">
<subject>1.继承BroadcastReceiver会重写哪一个方法()。subject>
<a>onReceiver()a>
<b>onUpdate()b>
<c>onCreate()c>
<d>onStart()d>
<answer>1answer>
exercises>
<exercises id="2">
<subject>2.关于广播的作用,说法正确的是()。subject>
<a>它主要用来接收系统发布的一些消息的a>
<b>它可以进行耗时的操作b>
<c>它可以启动一个Activityc>
<d>它可以帮助Actvity修改用户界面d>
<answer>1answer>
exercises>
<exercises id="3">
<subject>3.下列方法中,用于发送一条有序广播的是()。subject>
<a>startBroadcastReceiver()a>
<b>sendOrderedBroadcast()b>
<c>sendBroadcast()c>
<d>sendReceiver()d>
<answer>2answer>
exercises>
<exercises id="4">
<subject>4.在清单文件中,注册广播时使用的节点是()。subject>
<a>activitya>
<b>broadcastb>
<c>receiverc>
<d>broadcastreceiverd>
<answer>3answer>
exercises>
<exercises id="5">
<subject>5.关于BroadcastReceiver说法不正确的是()。subject>
<a>是用来接收广播Intent的a>
<b>一个广播Intent只能被一个订阅了此广播的BroadcastReceiver所接收b>
<c>对有序广播,系统会根据接收者声明的优先级别按顺序逐个执行接收者c>
<d>接收者声明的优先级别在android:priority属性中声明,数值越大优先级别越高d>
<answer>2answer>
exercises>
infos>
chapter8.xml
<infos>
<exercises id="1">
<subject>1.每一次启动服务都会调用什么方法()。subject>
<a>onCreate()a>
<b>onStart()b>
<c>onResume()c>
<d>onStartCommand()d>
<answer>4answer>
exercises>
<exercises id="2">
<subject>2.下列选项中,不属于绑定服务的特点的是()。subject>
<a>以bindService()方法开启a>
<b>调用者关闭后服务关闭b>
<c>必须实现ServiceConnection()c>
<d>使用stopService()方法关闭服务d>
<answer>4answer>
exercises>
<exercises id="3">
<subject>3.Service与Activity的共同点是()。subject>
<a>都是四大组件之一a>
<b>都有onResume()方法b>
<c>都不可以被远程调用c>
<d>都可以自定义美观界面d>
<answer>1answer>
exercises>
<exercises id="4">
<subject>4.下列方法中,不属于Service生命周期的是()。subject>
<a>onResume()a>
<b>onStart()b>
<c>onStop()c>
<d>onDestoryd>
<answer>1answer>
exercises>
<exercises id="5">
<subject>5.关于Service生命周期的onCreate()和onStart()方法,说法正确的是()。subject>
<a>如果Service已经启动,将先后调用onCreate()和onStart()方法a>
<b>如果Service已经启动,只会执行onCreate()方法b>
<c>当第一次启动的时候只会调用onCreate()方法c>
<d>如果Service已经启动,只会执行onStart()方法,不再执行onCreate()方法d>
<answer>4answer>
exercises>
infos>
chapter9.xml
<infos>
<exercises id="1">
<subject>1.下列选项中,不属于Handler机制中的关键对象的是()。subject>
<a>Contenta>
<b>Handlerb>
<c>MessageQueuec>
<d>Looperd>
<answer>1answer>
exercises>
<exercises id="2">
<subject>2.下列通讯方式中,不是Android系统提供的是()。subject>
<a>Socket通信a>
<b>HTTP通信b>
<c>URL通信c>
<d>以太网通信d>
<answer>4answer>
exercises>
<exercises id="3">
<subject>3.关于HttpURLConnection访问网络的基本用法,描述错误的是()。subject>
<a>HttpURLConnection对象需要设置请求网络的方式a>
<b>HttpURLConnection对象需要设置超时时间b>
<c>需要通过new关键字来创建HttpURLConnection对象c>
<d>访问网络完毕需要关闭http链接d>
<answer>3answer>
exercises>
<exercises id="4">
<subject>4.下列选项中,不属于AsyncHttpClient特点的是()。subject>
<a>发送异步HTTP请求a>
<b>HTTP请求发生在UI线程之外b>
<c>内部采用了线程池来处理并发请求c>
<d>自动垃圾回收d>
<answer>4answer>
exercises>
<exercises id="5">
<subject>5.下列选项中,关于GET和POST请求方式,描述错误的是()。subject>
<a>使用GET方式访问网络URL的长度是有限制的a>
<b>HTTP协议规定GET方式请求URL的长度不超过2kb>
<c>POST方式对URL的长度是没有限制的c>
<d>GET请求方式向服务器提交的参数跟在请求URL后面d>
<answer>2answer>
exercises>
infos>
chapter10.xml
<infos>
<exercises id="1">
<subject>1.使用MediaPlayer播放保存在sdcard上的mp3文件时()。subject>
<a>需要使用MediaPlayer.create方法创建MediaPlayera>
<b>不能直接new MediaPlayer即可b>
<c>直接使用setDataSource方法设置文件源c>
<d>直接调用start方法,无需设置文件源d>
<answer>3answer>
exercises>
<exercises id="2">
<subject>2.下列不属于补间动画相关的类是()。subject>
<a>TranslateAnimationa>
<b>FrameAnimationb>
<c>RotateAnimationc>
<d>AlphaAnimationd>
<answer>2answer>
exercises>
<exercises id="3">
<subject>3.有关于Fragment说法正确的是()。subject>
<a>使用Fragment必须在布局文件中加入fragment控件a>
<b>Fragment有自己的界面和生命周期,可以完全替代Activityb>
<c>Fragment的状态跟随它所关联的Activity的状态改变而改变c>
<d>当Fragment停止时,与它关联的Activity也会停止d>
<answer>3answer>
exercises>
<exercises id="4">
<subject>4.MediaPlayer播放资源前,需要调用哪个方法完成准备工作()。subject>
<a>setDataSourcea>
<b>prepareb>
<c>beginc>
<d>paused>
<answer>2answer>
exercises>
<exercises id="5">
<subject>5.下面属于Android动画分类的有()。subject>
<a>Tweensa>
<b>Frameb>
<c>Drawc>
<d>Animationd>
<answer>2answer>
exercises>
infos>
参考资料:《android项目实战——博学谷》(黑马程序员著)