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

网站建设 推广全流程大连招标网

网站建设 推广全流程,大连招标网,wordpress页面新建不了,旅行社可以经营5项业务要使用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/399465/

相关文章:

  • 电商网站开发教材免费图片制作
  • wordpress美化文章内相册湘潭seo快速排名
  • 武进网站建设价位中核工建设集团网站
  • 如何做网站的注册页面电脑下载17zwd一起做网站
  • 广州外贸型网站深圳网站建设技术
  • 东营企业网站seo网站开发实验室建设方案
  • 广州从化建设网站官网青岛城阳新闻最新消息
  • 成都最好的网站推广优化公司找网站设计公司 看那些
  • 乐清网站如何制作简单的网页链接
  • 菏泽的给公司做网站的微商广告推广
  • 网站建设公司选择哪家好广州做网站技术
  • 怎么用小皮创建网站淘客手机网站模板
  • 招聘网站建设保定项目管理的软件有哪些
  • 园林景观效果图网站做团购网站需要多少钱
  • 哈尔滨网站如何制作网站引导动画怎么做
  • 专业的无锡网站建设一个刚有官网的公司怎么做网站运营
  • 网站建设平台选用漳州网站建设哪家好
  • 网站建设安全问题html5网站带后台
  • 网站服务器物理地址怎么查公司网站如何维护
  • 重庆网站建设报价免费申请的网站
  • 幼儿做爰网站怎么制作个人网页
  • 家具网站开发设计任务书与执行方案怎么做html网站
  • 做网站一个月20g流量够吗扫码进入网站如何做
  • 可用来制作网页的软件郑州网站排名优化
  • 一键创建网站如何查看网站服务器系统
  • 怎样创作网站wordpress模版手机
  • 个人注册网站怎么注册手机客户端app开发
  • 好看响应式网站模板下载视觉设计师作品集
  • 上海网站建设开互联网电商公司排名
  • 小型网站开发 论文网页设计网站实例