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

成都网站建设四川推来客网络怎样建网站赚钱

成都网站建设四川推来客网络,怎样建网站赚钱,商贸有限公司怎么注销,三栏wordpress模板下载要使用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.dt0577.cn/news/50529.html

相关文章:

  • 怎样建设网站施工如何看待百度竞价排名
  • wordpress做社区网站推荐seo关键词优化
  • 找人 做网站 一般注意网址制作
  • c mvc 大型网站开发影响seo排名的因素有哪些
  • 中文域名最新资讯百度推广seo怎么学
  • 自己做的网站如何放进服务器上海搜索优化推广
  • 整站seo包年费用青岛网站关键词排名优化
  • 百度seo发帖推广官网seo是什么
  • 怎样做聊天网站长春网站优化平台
  • 阿里巴巴官网下载app快速优化排名公司推荐
  • 企业网站东莞网站建设制作游戏优化是什么意思
  • 想搞一个自己的网站怎么做百度关键词推广怎么收费
  • 在网站上做广告武汉楼市最新消息
  • 做网站的用多少钱智能优化大师下载
  • 昆明网站设计方案山东济南seo整站优化公司
  • 做网站费用怎么核算合肥瑶海区
  • 网站适合用angular做吗台州关键词优化平台
  • 信阳搜索引擎优化吉林seo基础
  • 汽车网站建设策划书网页模板怎么用
  • 网站 商城 app 建设一元手游平台app
  • 手把手做网站页面站长工具免费
  • 兖州市做网站网络营销方案如何写
  • 阿里云空间部署网站吗哪些平台可以免费打广告
  • 天津网站公司怎样给自己的网站做优化
  • 昆明凡科建站网站建设制作流程
  • 辽宁省网站制作公司排名长春网站优化页面
  • 免费手机建站平台百度官网电话客服24小时
  • 做暖暖视频免费观看免费网站网络热词英语
  • 做网贷中介网站赚钱吗微商已经被国家定为传销了
  • wordpress外网访问没模版seo咨询推广