程序员面试题网站,Android 天气APP(5),这里有份超全Android体系化进阶学习图谱

<androidx.recyclerview.widget.RecyclerView

android:id=“@+id/rv_search”

android:visibility=“gone”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:scrollbars=“none” />

可以看到这里布局和搜索城市的布局有些类似,但不一样,这里的搜索出来的结果不会产生搜索记录,当点击搜索出来的城市时,就去查询这个城市的天气,同时这个城市也会放入常用城市列表里面,这里可以用缓存来做处理,也可以通过数据库来处理。

② Android SQLite

相信很多从事Android开发的程序员都了解过SQLite,但是用过的人并不多,这是为什么呢?因为一旦数据量很多的情况下我们不会用SQLite,而是通过服务器的数据库返回数据,而数据量少的时候用缓存就可以解决问题,所以这也是SQLite尴尬的地方,这是我个人看法,不过这个SQLite还是很重要的,不然我还是会用缓存的,如果是使用原生的SQLite代码就会比较的繁琐,所以这里我们可以用第三方库来快速实现功能,这里使用郭霖大神的LitePal框架

首先是在mvplibrary下的build.gradle中添加依赖

//Android SQLite操作框架

api ‘org.litepal.guolindev:core:3.1.1’

//列表item侧滑删除

api ‘com.github.mcxtzhang:SwipeDelMenuLayout:V1.3.0’

在这里插入图片描述

应该是一目了然吧,记得Sync哦~

然后配置litepal.xml,将项目预览模式切换为Project,然后打开mvplibrary,创建一个assets文件夹,再创建一个litepal.xml文件

在这里插入图片描述

文件中的代码如下

<?xml version="1.0" encoding="utf-8"?>

比较的简单

然后要在app下的WeatherApplication中进行初始化

在这里插入图片描述

现在你可以创建数据实体了,然后在mvplibrary下创建一个数据实体bean

在这里插入图片描述

代码如下:

package com.llw.mvplibrary.bean;

import org.litepal.crud.LitePalSupport;

public class ResidentCity extends LitePalSupport {

private int id;//编号

private String location;//地区/城市名称

private String parent_city;//该地区/城市的上级城市

private String admin_area;//该地区/城市所属行政区域

private String cnty;//该地区/城市所属国家名称

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public String getLocation() {

return location;

}

public void setLocation(String location) {

this.location = location;

}

public String getParent_city() {

return parent_city;

}

public void setParent_city(String parent_city) {

this.parent_city = parent_city;

}

public String getAdmin_area() {

return admin_area;

}

public void setAdmin_area(String admin_area) {

this.admin_area = admin_area;

}

public String getCnty() {

return cnty;

}

public void setCnty(String cnty) {

this.cnty = cnty;

}

}

然后在litepal.xml中增加一个mapping

在这里插入图片描述

最后在WeatherApplication中的onCreate方法中初始化,初始化的时候,你的数据库就创建好了,数据库名称是GoodWeather,表名是ResidentCity

在这里插入图片描述

那么这一块的内容就写完了,只需要在实际应用中结合业务逻辑使用就可以了,当然你也可以去自己尝试一下,感兴趣的可以看Android LitePal的简单使用这篇文章。

③ 布局item

通过最上面的效果图可以看到是两个列表,其中一个是已经添加的城市列表,另一个是搜索出来的城市列表,既然两个列表就要有两个item,当然你也可以用一个item来写,只不过用的时候要多写一些代码,首先当然是从布局开始着手了。

在这里插入图片描述

在app中res下的layout中创建两个布局文件

item_commonly_city_list.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout android:orientation=“vertical”

xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”>

<com.mcxtzhang.swipemenulib.SwipeMenuLayout

xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“@dimen/dp_50”

android:clickable=“true”

android:paddingBottom=“1dp”>

<TextView

android:id=“@+id/tv_city_name”

android:gravity=“center_vertical”

android:paddingLeft=“@dimen/dp_16”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:textColor=“@color/shallow_black”

android:background=“?android:attr/selectableItemBackground”

android:text=“城市”/>

<Button

android:id=“@+id/btn_delete”

android:layout_width=“@dimen/dp_100”

android:layout_height=“match_parent”

android:background=“@color/red”

android:text=“删除”

android:textColor=“@android:color/white”/>

</com.mcxtzhang.swipemenulib.SwipeMenuLayout>

<View

android:background=“@color/line_gray”

android:layout_width=“match_parent”

android:layout_height=“@dimen/dp_1”/>

item_commonly_city_add_list.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:app=“http://schemas.android.com/apk/res-auto”

android:layout_width=“match_parent”

android:id=“@+id/item_add_city”

android:background=“?android:attr/selectableItemBackground”

android:layout_height=“wrap_content”

android:orientation=“vertical”>

<TextView

android:id=“@+id/tv_location”

android:gravity=“center_vertical”

android:layout_width=“match_parent”

android:textSize=“@dimen/sp_16”

android:paddingLeft=“@dimen/dp_16”

android:layout_height=“@dimen/dp_50”

android:textColor=“@color/shallow_black” />

<View

android:layout_width=“match_parent”

android:layout_height=“@dimen/dp_1”

android:background=“@color/line_gray” />

④ 列表适配器

然后创建适配器

在这里插入图片描述

CommonlyCityAdapter.java

package com.llw.goodweather.adapter;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;

import com.chad.library.adapter.base.BaseViewHolder;

import com.llw.goodweather.R;

import com.llw.mvplibrary.bean.ResidentCity;

import java.util.List;

/**

  • 常用城市列表适配器

*/

public class CommonlyCityAdapter extends BaseQuickAdapter<ResidentCity, BaseViewHolder> {

public CommonlyCityAdapter(int layoutResId, @Nullable List data) {

super(layoutResId, data);

}

@Override

protected void convert(BaseViewHolder helper, ResidentCity item) {

helper.setText(R.id.tv_city_name, item.getLocation());

//添加点击事件

helper.addOnClickListener(R.id.tv_city_name)

.addOnClickListener(R.id.btn_delete);

}

}

CommonlyCityAddAdapter.java

package com.llw.goodweather.adapter;

import android.text.SpannableStringBuilder;

import android.text.style.ForegroundColorSpan;

import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;

import com.chad.library.adapter.base.BaseViewHolder;

import com.llw.goodweather.R;

import com.llw.goodweather.bean.SearchCityResponse;

import java.util.List;

import static android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;

/**

  • 添加城市时搜索返回结果列表适配器

*/

public class CommonlyCityAddAdapter extends BaseQuickAdapter<SearchCityResponse.HeWeather6Bean.BasicBean, BaseViewHolder> {

private String edStr;//关键字

public CommonlyCityAddAdapter(int layoutResId, @Nullable List<SearchCityResponse.HeWeather6Bean.BasicBean> data) {

super(layoutResId, data);

}

@Override

protected void convert(BaseViewHolder helper, SearchCityResponse.HeWeather6Bean.BasicBean item) {

TextView textView = helper.getView(R.id.tv_location);

String result = item.getLocation() + " , " + item.getParent_city() + " , " + item.getAdmin_area() + " , " + item.getCnty();

if (edStr != null && edStr.length() > 0) {

textView.setText(matcherSearchText(mContext.getResources().getColor(R.color.shallow_yellow),result,edStr));

} else {

textView.setText(item.getLocation() + " , " +

item.getParent_city() + " , " +

item.getAdmin_area() + " , " +

item.getCnty());

}

helper.addOnClickListener(R.id.item_add_city);

}

/**

  • 改变颜色

  • @param str 输入的文本

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)
img

学习福利

【Android 详细知识点思维脑图(技能树)】

其实Android开发的知识点就那么多,面试问来问去还是那么点东西。所以面试没有其他的诀窍,只看你对这些知识点准备的充分程度。so,出去面试时先看看自己复习到了哪个阶段就好。

虽然 Android 没有前几年火热了,已经过去了会四大组件就能找到高薪职位的时代了。这只能说明 Android 中级以下的岗位饱和了,现在高级工程师还是比较缺少的,很多高级职位给的薪资真的特别高(钱多也不一定能找到合适的),所以努力让自己成为高级工程师才是最重要的。

这里附上上述的面试题相关的几十套字节跳动,京东,小米,腾讯、头条、阿里、美团等公司19年的面试题。把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节。

由于篇幅有限,这里以图片的形式给大家展示一小部分。

网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。

本文已被CODING开源项目:《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》收录

一个人可以走的很快,但一群人才能走的更远。如果你从事以下工作或对以下感兴趣,欢迎戳这里加入程序员的圈子,让我们一起学习成长!

AI人工智能、Android移动开发、AIGC大模型、C C#、Go语言、Java、Linux运维、云计算、MySQL、PMP、网络安全、Python爬虫、UE5、UI设计、Unity3D、Web前端开发、产品经理、车载开发、大数据、鸿蒙、计算机网络、嵌入式物联网、软件测试、数据结构与算法、音视频开发、Flutter、IOS开发、PHP开发、.NET、安卓逆向、云计算

,腾讯、头条、阿里、美团等公司19年的面试题。把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节。

由于篇幅有限,这里以图片的形式给大家展示一小部分。

[外链图片转存中…(img-1gRTbfTn-1712527589205)]

网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。

本文已被CODING开源项目:《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》收录

一个人可以走的很快,但一群人才能走的更远。如果你从事以下工作或对以下感兴趣,欢迎戳这里加入程序员的圈子,让我们一起学习成长!

AI人工智能、Android移动开发、AIGC大模型、C C#、Go语言、Java、Linux运维、云计算、MySQL、PMP、网络安全、Python爬虫、UE5、UI设计、Unity3D、Web前端开发、产品经理、车载开发、大数据、鸿蒙、计算机网络、嵌入式物联网、软件测试、数据结构与算法、音视频开发、Flutter、IOS开发、PHP开发、.NET、安卓逆向、云计算

  • 12
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值