当前位置: 首页 > news >正文

建站服务是什么泰安有什么互联网公司

建站服务是什么,泰安有什么互联网公司,电商运营有几大平台,给网站定位要使用RecyclerView显示天气预报的内容 先在grandle里添加recyclerView的引用 implementation androidx.recyclerview:recyclerview:1.3.1创建一个RecyclerView控件:在布局文件中,添加一个RecyclerView控件,用于显示天气预报的列表。 这是一…

要使用RecyclerView显示天气预报的内容

  1. 先在grandle里添加recyclerView的引用
    implementation 'androidx.recyclerview:recyclerview:1.3.1'
  1. 创建一个RecyclerView控件:在布局文件中,添加一个RecyclerView控件,用于显示天气预报的列表。
    这是一个包含三个TextView的LinearLayout布局,用于显示天气相关的数据。每个TextView都有一个唯一的id,可用于在代码中找到和操作它们。

TextView的id为weatherData,用于显示天气数据。
TextView的id为weatherDescription,用于显示天气描述。
TextView的id为weatherTemperature,用于显示天气温度。
LinearLayout的属性设置如下:
android:layout_width和android:layout_height分别设置为match_parent和wrap_content,使得布局宽度填充父容器,高度根据内容自适应。
android:layout_marginLeft和android:layout_marginRight设置为10dp,给左右两侧的边距留出10dp的空间。这样可以让布局与父容器的边缘有一个间隔。

每个TextView的属性设置如下:
android:layout_width和android:layout_height都设置为wrap_content,使得TextView的大小根据内容自适应。
android:layout_weight设置为1,表示每个TextView在水平方向上平均分配可用的空间。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"><TextViewandroid:id="@+id/weatherData"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"/><TextViewandroid:id="@+id/weatherDescription"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"/><TextViewandroid:id="@+id/weatherTemperature"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"/></LinearLayout>
  1. 创建RecyclerView的适配器:创建一个继承自RecyclerView.Adapter的适配器类,用于将数据绑定到RecyclerView的子项上。
package com.example.myweather.openWeatherMapimport android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.myweather.R
import java.text.SimpleDateFormat
import java.util.*class ForecastAdapter(private val forecastList: List<ForecastCell>) :RecyclerView.Adapter<ForecastAdapter.ViewHolder>() {inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {val weatherData: TextView = view.findViewById(R.id.weatherData)val weatherDescription: TextView = view.findViewById(R.id.weatherDescription)val weatherTemperature: TextView = view.findViewById(R.id.weatherTemperature)}override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {val view = LayoutInflater.from(parent.context).inflate(R.layout.weather_item, parent, false)return ViewHolder(view)}@SuppressLint("SetTextI18n")override fun onBindViewHolder(holder: ViewHolder, position: Int) {val kelvins = 273.15val simpleDateFormat = SimpleDateFormat("MM-dd HH:mm", Locale.ENGLISH)val forecastCell = forecastList[position]holder.weatherData.text = simpleDateFormat.format(forecastCell.dt*1000L)holder.weatherDescription.text = forecastCell.weather.first().descriptionholder.weatherTemperature.text = "${forecastCell.main.maxTemperature.minus(kelvins).toInt()}/" +"${forecastCell.main.minTemperature.minus(kelvins).toInt()}"}override fun getItemCount() = forecastList.size
}
  1. 设置RecyclerView的布局管理器和适配器
private lateinit var forecastRecyclerView: RecyclerViewoverride fun onCreate(savedInstanceState: Bundle?) {//...forecastRecyclerView = findViewById(R.id.forecastRecyclerView)forecastRecyclerView.layoutManager = LinearLayoutManager(this)//...
}private fun updateForecastList(forecastResponse: ForecastResponse) {val adapter = ForecastAdapter(forecastResponse.forecastCellList!!)forecastRecyclerView.adapter = adapter}

在上面的代码中,forecastCellList是包含天气预报数据的List集合。

  1. 提供数据并更新适配器:在您的Activity或Fragment中,提供天气预报数据并通知适配器更新数据。
    当eventbus收到ForecastReponseEvent后,会调用updateForecastList(),去更新ForecastRecyclerView的adapter。
    private fun updateForecastList(forecastResponse: ForecastResponse) {val adapter = ForecastAdapter(forecastResponse.forecastCellList!!)forecastRecyclerView.adapter = adapter}
http://www.yayakq.cn/news/598504/

相关文章:

  • 下载室内设计排版模板网站有哪些建站源码
  • wordpress公司网站模板浙江恒元建设网站
  • 营销广告广州seo关键词优化是什么
  • 怎么做网站优化排名到前面西安网站建设制作价格低
  • 阿里云服务器 放多个网站制作视频的软件app免费
  • 网站关键词怎么做可以排名漳州企业网站建设制作
  • 做羞羞的事的视频网站宁德城乡建设部网站首页
  • 建立公司网站采购网站有哪些
  • 南宁专业网站开发如何注册chn域名网站
  • 网站程序开发费用简单大气静态网页模板
  • 英文杭州网站建设wordpress网站图片迁移
  • 用户搭建网站青岛黄岛区网站开发
  • 网站设计深圳公司中山做网站好的公司
  • 商城网站建设要多少钱网站改版方案原则
  • 支付网站怎么设计的黄陂机械加工网
  • 做个人网站需要哪些如网站性质为公司 请以企业备案
  • 企业网站建设论文网站建设 千佳网络
  • 茂名网站建设公司电商网站目录优化
  • 个人网站域名所有权织梦网站一排4张图片
  • 哈尔滨房地产网站建设seo排名外包
  • 怎么用上线了做网站郑州自建网站
  • 服务网站排名咨询数字营销策划
  • php多平台商城网站系统建设怎样做网站的背景图片
  • 盗用网站模板网站建设列入管理费用说明科目
  • 网站开发的目的意义哪个网站可以做设计比赛
  • 网站建设网页怎么排列顺序购物网站模板 php
  • 网站去掉后缀htmlasp网站开发的主要困难
  • 网站开发文档带er图wordpress执行流程
  • 软件技术属于什么学类东莞市seo网络推广怎么样
  • 上行30m可以做网站吗慧算账代理记账公司