GithubHelp home page GithubHelp logo

androidhomework2's Introduction

浙江大学安卓开发小学期 作业2

姓名:朱璟森

学号:3170104166

专业:计算机科学与技术


作业要求

创建一个Android app工程,使用RecyclerView,实现一个类似于热榜的列表。

作业实现

注:为了节省代码量,本次作业中的所有回调事件全部采用Lambda 表达式进行编写而非传统的new OnClickListener() {@Override ......}的形式。

本次作业共实现两个Activity,一个为登录界面,一个为热榜界面。

登录界面如下:

1562678302810

其中要求学号为10位数字,密码不得小于6位,否则会在Toast上弹出错误提示,无法进入下一界面。

点击“注册或登录”按钮进入热榜界面如下,是一个游戏排行榜的界面:

1562678486257

其中的热榜可以自由滑动。热榜前三的排名为黄色,与其他的浅蓝色不同。

进阶要求

本次作业实现了3个进阶要求:在ItemDecoration中增加分割线,在列表中增加元素,以及列表元素的点击事件。

分割线

分割线的实现十分简单,只需一行代码:

mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));

分割线效果如上文中截图所示。

增加元素

如上图,顶部有一个“添加”的按钮,点击就会弹出对话框:

1562678796935

输入名称与热度并点击“确定”就会将新的元素插入到列表中,且列表中的元素会按照热度进行重新排序,如输入“LOL”、13000后,热榜变为:

1562678916039

对话框的实现用到了AlertDialog类,为其制定自定义布局 (输入框),并设置确定与取消按钮的回调函数。确定按钮的回调函数将输入的内容插入到AdapterList中,并对List进行重新排序,最后调用notifyDataSetChanged函数更新列表。而取消按钮则会在Toast中弹出“已取消”的提示。

元素点击事件

在热榜中,点击任意一个元素会弹出一个AlertDialog对话框,其标题为排名,正文内容为游戏名称与热度值,如图:

1562679184287

点击事件的实现为:在Adapter中的onBindViewHolder函数中,为holder.itemView设置onClickListener即可。

心得

本次作业使用了RecyclerView,巩固了上课内容,对Adapter, ViewHolder的使用增进了理解。而在进阶要求的实现中,通过上网搜索,自学了许多内容,收获颇丰。

androidhomework2's People

Contributors

jingsenzhu avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.