Android MVP实战——环境云API+Android实现天气预报查询(下)

Android MVP实战——环境云API+Android实现天气预报查询(上)中,我们已经完成了基本的准备工作。接下来我们就将具体去实现业务逻辑。在本节中,将会涉及到volley以及gson的基本使用,如果有不会的小伙伴建议提前学习一下。


一、设计UI

1、在view.impl包下建立一个空的Activity,命名为WeatherActivity。

这里写图片描述

2、编辑`res/layout/activity_weather.xml布局文件,我们的UI非常简单,总共使用到了3个组件AutoComleteTextView+Button+ListView

代码如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.leven.weatherdemo.view.impl.WeatherActivity">

    <AutoCompleteTextView
        android:id="@+id/atv_city_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:hint="请输入城市名称"
        android:completionThreshold="1"/>

    <Button
        android:id="@+id/btn_submit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/atv_city_name"
        android:layout_below="@+id/atv_city_name"
        android:text="查询" />

    <ListView
        android:id="@+id/listView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/btn_submit" />

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/btn_submit"
        android:layout_alignParentStart="true"
        android:indeterminate="false" />

</RelativeLayout>

效果图:
这里写图片描述

3、编写WeatherActivity

上一节中,我们在view包下建立一个接口WeatherView接口,而我们的WeatherActivity就是WeatherView的具体实现类,所以WeatherActivity要去实现WeatherView接口,用来显示我们的天气数据。但在实现WeatherActivity之前呢,我们还需做一点点小小的准备工作。

准备①:因为我们使用了ListView来显示数据,所以我们还要自定义一个Adapter适配器,当然还可以使用SimpleAdapter等,这个看个人喜好啦,我还是喜欢使用自定义Adapter,因为这样更加灵活,详细代码如下:
1、在adapter包下建立ListItemAdapter

package com.leven.weatherdemo.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.leven.weatherdemo.R;

/**
 * list适配器
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值