基于eclipse的android项目实战 | 您所在的位置:网站首页 › 安卓导航ui与mcu不匹配怎么回事 › 基于eclipse的android项目实战 |
本项目是用eclipse软件编写,经过我的亲自实践,其真实有效,希望能给您有所帮助😘😘 项目版本:android5.1.1 AVD建议:android4.4.2及以上 若有不足之处或不对的地方,欢迎大佬们指点
BoXueGu源码资源下载链接: https://download.csdn.net/download/hyh/19477319 BoXueGu图片资源下载(免费): https://yuyunyaohui.lanzoui.com/iWos0pyc4rc 效果图:将习题界面所需图片 exercises_bg_1.png、exercises_bg_2.png、exercises_bg_3.png、exercises_bg_4.png导入drawable文 件夹中 res/layout文件夹中新建main_view_exercises.xml文件,代码如下: 3.习题界面ItemItem界面展示章节序号、章节名称以及该章节所包含的题目数量 在res/layout文件夹中,创建一个布局文件exercises_list_item.xml 在values文件夹下的string.xml文件里面输入文本信息: 第1章Android基础入门 共计5题 4.创建ExercisesBean创建ExercisesBean类用来存放章节及习题所包含的相关属性 每个章节所包含的属性有章节Id、章节标题、习题数量、章节序号背景、习题Id、习题题干、习题的A选项、 B选项、C选项、D选项、正确答案以及被用户选中的选项等。 在china.ynyx.heyunhui.bean包中创建一个ExercisesBean类,具体代码如下: package china.ynyx.heyunhui.bean; public class ExercisesBean { public int id;// 每章习题id public String title;// 每章习题标题 public String content;// 每章习题的数目 public int background;// 每章习题前边的序号背景 public int subjectId;// 每道习题的Id public String subject;// 每道习题的题干 public String a;// 每道题的A选项 public String b;// 每道题的B选项 public String c;// 每道题的C选项 public String d;// 每道题的D选项 public int answer;// 每道题的正确答案 public int select;// 用户选中的那项(0表示所选项对了,1表示A选项错,2表示B选项错,3表示C选项错,4表示D选项错) } 5.习题界面Adapter创建一个数据适配器对ListView进行数据适配。 选中china.ynyx.heyunhui包,在该包下创建china.ynyx.heyunhui.adapter包,在.adapter包中创建一个ExercisesAdapter 类继承 BaseAdapter 类 习题界面主要用于展示《Android移动开发基础案例教程》1〜10章的习题。我们可以将数据信息封装到ExercisesBean对象中,在习题界面进行展示。 在china.ynyx.heyunhui.view包中创建一个ExercisesView类 具体代码如下:ExercisesView.java package china.ynyx.heyunhui.view; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.view.LayoutInflater; import android.view.View; import android.widget.ListView; import china.ynyx.heyunhui.R; import china.ynyx.heyunhui.adapter.ExercisesAdapter; import china.ynyx.heyunhui.bean.ExercisesBean; public class ExercisesView { private ListView lv_list; private ExercisesAdapter adapter; private List ebl; private Activity mContext; private LayoutInflater mInflater; private View mCurrentView; public ExercisesView(Activity context) { mContext = context; // 为之后将Layout转化为view时用 mInflater = LayoutInflater.from(mContext); } private void createView() { initView(); } /** * 初始化控件 */ private void initView() { mCurrentView = mInflater .inflate(R.layout.main_view_exercises, null); lv_list = (ListView) mCurrentView.findViewById(R.id.lv_list); adapter = new ExercisesAdapter(mContext); initData(); adapter.setData(ebl); lv_list.setAdapter(adapter); } /** * 设置数据 * 首先创建ExercisesBean对象,之后 将每一章的章节Id、章节标题、习题数量和序号背景存入ExercisesBean对象中 */ private void initData() { ebl = new ArrayList(); for (int i = 0; i case 0: bean.title="第1章 Android基础入门"; bean.content="共计5题"; bean.background=(R.drawable.exercises_bg_1); break; case 1: bean.title="第2章 Android UI开发"; bean.content="共计5题"; bean.background=(R.drawable.exercises_bg_2); break; case 2: bean.title="第3章 Activity"; bean.content="共计5题"; bean.background=(R.drawable.exercises_bg_3); break; case 3: bean.title="第4章 数据存储"; bean.content="共计5题"; bean.background=(R.drawable.exercises_bg_4); break; case 4: bean.title="第5章 SQLite数据库"; bean.content="共计5题"; bean.background=(R.drawable.exercises_bg_1); break; case 5: bean.title="第6章 广播接收者"; bean.content="共计5题"; bean.background=(R.drawable.exercises_bg_2); break; case 6: bean.title="第7章 服务"; bean.content="共计5题"; bean.background=(R.drawable.exercises_bg_3); break; case 7: bean.title="第8章 内容提供者"; bean.content="共计5题"; bean.background=(R.drawable.exercises_bg_4); break; case 8: bean.title="第9章 网络编程"; bean.content="共计5题"; bean.background=(R.drawable.exercises_bg_1); break; case 9: bean.title="第10章 高级编程"; bean.content="共计5题"; bean.background=(R.drawable.exercises_bg_2); break; default: break; } ebl.add(bean); } } /** * 获取当前在导航栏上方显示对应的View */ public View getView() { if (mCurrentView == null) { createView(); } return mCurrentView; } /** * 显示当前导航栏上方所对应的view界面 */ public void showView() { if (mCurrentView == null) { createView(); } mCurrentView.setVisibility(View.VISIBLE); } } 7.功能完善(1)修改底部导航栏 由于习题界面是通过底部导航栏界面跳转的,因此需要在“我的模块”中找到MainActivity.java 文件中如下代码: private ExercisesView mExercisesView;如图: 参考资料:《android项目实战——博学谷》(黑马程序员著) 基于eclipse的android项目实战—博学谷(一)欢迎界面 基于eclipse的android项目实战—博学谷(二)注册界面 基于eclipse的android项目实战—博学谷(三)登录界面 基于eclipse的android项目实战—博学谷(四)底部导航栏 基于eclipse的android项目实战—博学谷(五)“我”的模块 基于eclipse的android项目实战—博学谷(六)设置界面 基于eclipse的android项目实战—博学谷(七)修改密码 基于eclipse的android项目实战—博学谷(八)设置密保和找回密码 基于eclipse的android项目实战—博学谷(九)个人资料界面 基于eclipse的android项目实战—博学谷(十)个人资料修改 基于eclipse的android项目实战—博学谷(十 一)习题界面 基于eclipse的android项目实战—博学谷(十二)习题详情界面 基于eclipse的android项目实战—博学谷(十三)水平滑动广告栏界面 基于eclipse的android项目实战—博学谷(十四)课程界面 基于eclipse的android项目实战—博学谷(十五)课程详情界面 基于eclipse的android项目实战—博学谷(十六)视频播放界面 基于eclipse的android项目实战—博学谷(十七)播放记录界面 基于eclipse的android项目实战—博学谷(十八)播放不同视频(网络视频) 基于eclipse的android项目实战—博学谷(十九)播放不同视频(本地视频) |
CopyRight 2018-2019 实验室设备网 版权所有 |