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

网站推广渠道及特点微信运营方案

网站推广渠道及特点,微信运营方案,二维码生成网址链接,重庆网站建设制作公司增加界面显示openweathermap返回的信息。 在activity_main.xml里增加输入框来输入城市&#xff0c;在输入款旁边增加搜索按钮来进行查询。 然后原来显示helloworld的TextView用来显示结果。 1. 增加输入城市名字的EditText <EditTextandroid:id"id/editTextCity"…

增加界面显示openweathermap返回的信息。

在activity_main.xml里增加输入框来输入城市,在输入款旁边增加搜索按钮来进行查询。
然后原来显示helloworld的TextView用来显示结果。

1. 增加输入城市名字的EditText

    <EditTextandroid:id="@+id/editTextCity"android:layout_width="0dp"android:layout_height="wrap_content"android:hint="@string/editTextCityHint"app:layout_constraintTop_toTopOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintEnd_toStartOf="@+id/buttonSearch"/>
  1. 增加搜索按钮
    <Buttonandroid:id="@+id/buttonSearch"android:layout_width="wrap_content"android:layout_height="wrap_content"app:layout_constraintTop_toTopOf="@+id/editTextCity"app:layout_constraintBottom_toBottomOf="@+id/editTextCity"app:layout_constraintStart_toEndOf="@+id/editTextCity"app:layout_constraintEnd_toEndOf="parent"android:text="@string/buttonSearchText" />

3. 增加显示的TextView

    <TextViewandroid:id="@+id/weatherResult"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello World!"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" />

使用broadcast的方式把收到的天气信息发送到界面显示。
Android的广播机制是一种用于在应用程序内和应用程序之间传递消息和事件的方式。通过广播,一个应用程序可以发送消息(被称为广播),而其他应用程序可以接收并处理这些广播。

  • 广播发送者(Broadcast Sender):应用程序或者系统组件(如系统服务)可以通过发送广播来通知其他应用程序或组件事件的发生。广播发送者并不需要知道接收者是谁,只需要发送广播即可。
  • 广播接收者(Broadcast Receiver):应用程序或者组件可以通过注册广播接收器来接收特定类型的广播。广播接收者可以在AndroidManifest.xml文件中声明静态接收器,也可以在代码中动态注册接收器。
  • 广播的类型:Android广播可以分为普通广播和有序广播两种类型。
  • 普通广播(Normal Broadcast):普通广播是一种异步的广播发送方式,广播发送者不需要等待接收者处理广播。这使得广播发送者能够快速地发送广播,而不会受到接收者处理时间的影响。
  • 有序广播(Ordered Broadcast):有序广播是一种同步的广播发送方式,广播发送者会按照优先级的顺序发送广播,接收者依次处理广播。每个接收者处理完广播后可以选择终止广播或者将广播传递给下一个接收者。
  • 广播过滤器(Broadcast Filter):广播过滤器允许应用程序指定它们所感兴趣的广播类型。广播接收者可以根据广播过滤器过滤来自特定来源或具有特定操作的广播。这样可以减少不必要的广播传递,提高性能。
  • 系统广播(System Broadcast):Android系统内置了一些广播用于通知应用程序和组件系统事件的发生,例如设备启动、网络连接状态变化、电池低电量等。应用程序可以注册对这些系统广播感兴趣的接收者,以执行相应的操作。
    通过广播机制,应用程序可以实现一种松耦合的通信方式,让不同的组件之间进行信息传递和事件触发。这种机制使得应用程序能够更好地响应系统事件、应用程序状态的变化,并且可以与其他应用程序之间进行交互。

4.注册一个自定义的广播:

将广播接收器的类名替换为您自己的接收器类名,并使用 intent-filter 添加您自定义的广播 action。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"><uses-permission android:name="android.permission.INTERNET" /><application
<!--   			... --><activity
<!--   			... --></activity><receiverandroid:name=".WeatherResponseReceiver"android:exported="false"><intent-filter><action android:name="com.example.MyWeather.ACTION_WEATHER_DATA"/></intent-filter></receiver></application></manifest>

5.在RetrofitClient类中发送广播

在发送自定义广播时,您需要使用 sendBroadcast() 方法,并指定广播的 action。

    private fun handleWeatherData(context: Context, weatherData: WeatherResponse?) {if (weatherData != null) {val intent = Intent("com.example.MyWeather.ACTION_WEATHER_DATA")intent.putExtra("cityName", weatherData.name)intent.putExtra("temperature", weatherData.main?.temp)intent.putExtra("maxTemperature", weatherData.main?.temp_max)intent.putExtra("minTemperature", weatherData.main?.temp_min)val weatherStringArray = arrayListOf<String>()for(weather in weatherData.weather) {weatherStringArray += "main:${weather.main},description:${weather.description}"}intent.putStringArrayListExtra("weather", weatherStringArray)context.sendBroadcast(intent)printWeatherData(weatherData)}}

6.创建一个用来接受广播的类,并重写onReceive函数。

class WeatherResponseReceiver : BroadcastReceiver() {private var textView: TextView? = nullfun setTextView(textView: TextView) {this.textView = textView}override fun onReceive(context: Context?, intent: Intent?) {if(intent?.action == "com.example.MyWeather.ACTION_WEATHER_DATA") {val kelvins = 273.15val cityName = intent.getStringExtra("cityName")val temperature = intent.getFloatExtra("temperature", 0.0F) - kelvinsval maxTemperature = intent.getFloatExtra("maxTemperature", 0.0F) - kelvinsval minTemperature = intent.getFloatExtra("minTemperature", 0.0F) - kelvinsval weather = intent.getStringArrayListExtra("weather")val decimalFormat = DecimalFormat("#.#")@SuppressLint("SetTextI18n")textView?.text = "$cityName\n${decimalFormat.format(temperature)}\n${decimalFormat.format(maxTemperature)}\n${decimalFormat.format(minTemperature)}\n$weather"}}
}

为了能让收到的广播消息能够显示在TextView中,我把TextView的指针传递给了接收广播的类。

class MainActivity : AppCompatActivity() {private lateinit var weatherResponseReceiver: WeatherResponseReceiveroverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)weatherResponseReceiver = WeatherResponseReceiver()weatherResponseReceiver.setTextView(findViewById<TextView>(R.id.weatherResult))val intentFilter = IntentFilter("com.example.MyWeather.ACTION_WEATHER_DATA")registerReceiver(weatherResponseReceiver, intentFilter)findViewById<Button>(R.id.buttonSearch).setOnClickListener { searchCityNameWeather(it) }}override fun onDestroy() {super.onDestroy()unregisterReceiver(weatherResponseReceiver)}private fun searchCityNameWeather(view: View) {val cityName = findViewById<EditText>(R.id.editTextCity).text.toString().trim()RetrofitClient.getWeatherByCityName(view.context, cityName)}
}

7.最后的测试结果:

在这里插入图片描述


文章转载自:
http://fortunate.fznj.cn
http://limner.fznj.cn
http://northeasterner.fznj.cn
http://vacuole.fznj.cn
http://picked.fznj.cn
http://eshaustibility.fznj.cn
http://tayal.fznj.cn
http://chimb.fznj.cn
http://panada.fznj.cn
http://gossamery.fznj.cn
http://bedsheet.fznj.cn
http://horatio.fznj.cn
http://silbador.fznj.cn
http://pepsin.fznj.cn
http://wuzzle.fznj.cn
http://fess.fznj.cn
http://et.fznj.cn
http://lawsoniana.fznj.cn
http://leafhopper.fznj.cn
http://fobs.fznj.cn
http://remainder.fznj.cn
http://earthen.fznj.cn
http://flinch.fznj.cn
http://trist.fznj.cn
http://skintight.fznj.cn
http://feelingful.fznj.cn
http://vizier.fznj.cn
http://seismogram.fznj.cn
http://premonstratensian.fznj.cn
http://prename.fznj.cn
http://steel.fznj.cn
http://unbraid.fznj.cn
http://lingam.fznj.cn
http://blur.fznj.cn
http://lumberly.fznj.cn
http://zenist.fznj.cn
http://blasphemer.fznj.cn
http://pursily.fznj.cn
http://hydrolyte.fznj.cn
http://caudate.fznj.cn
http://interdate.fznj.cn
http://rivalship.fznj.cn
http://anticorrosive.fznj.cn
http://shunpiker.fznj.cn
http://outcome.fznj.cn
http://bronzite.fznj.cn
http://kindling.fznj.cn
http://awninged.fznj.cn
http://roble.fznj.cn
http://spinnerette.fznj.cn
http://aldose.fznj.cn
http://contemporaneity.fznj.cn
http://eft.fznj.cn
http://pushup.fznj.cn
http://ret.fznj.cn
http://dehydrofreezing.fznj.cn
http://toltec.fznj.cn
http://sawan.fznj.cn
http://ostein.fznj.cn
http://doomsten.fznj.cn
http://rachides.fznj.cn
http://spontoon.fznj.cn
http://demonstrability.fznj.cn
http://wale.fznj.cn
http://hankou.fznj.cn
http://paralogism.fznj.cn
http://derivative.fznj.cn
http://petrify.fznj.cn
http://rhizopus.fznj.cn
http://inchoative.fznj.cn
http://sheading.fznj.cn
http://bicorn.fznj.cn
http://outdoorsman.fznj.cn
http://moderatism.fznj.cn
http://fictive.fznj.cn
http://redpoll.fznj.cn
http://publican.fznj.cn
http://bekaa.fznj.cn
http://oleaster.fznj.cn
http://dewalee.fznj.cn
http://thu.fznj.cn
http://bristol.fznj.cn
http://retreatant.fznj.cn
http://hardtop.fznj.cn
http://galactin.fznj.cn
http://charactonym.fznj.cn
http://saka.fznj.cn
http://crackled.fznj.cn
http://coalescent.fznj.cn
http://antitubercular.fznj.cn
http://vituperate.fznj.cn
http://pinwheel.fznj.cn
http://operculiform.fznj.cn
http://resistant.fznj.cn
http://dioxane.fznj.cn
http://halma.fznj.cn
http://aqueous.fznj.cn
http://encyclopaedist.fznj.cn
http://content.fznj.cn
http://kingsoft.fznj.cn
http://www.dt0577.cn/news/97913.html

相关文章:

  • 网站如何做快排视频推广渠道有哪些
  • 可以做自媒体的网站女教师遭网课入侵直播
  • 做周边的专业网站免费培训机构管理系统
  • 做企业销售分析的网站seo技巧分享
  • 东莞住建局官方网站优化电脑的软件有哪些
  • 广州网站建设吧seo01网站
  • qq浏览器小程序廊坊seo关键词排名
  • 做网站app需要懂些什么网红推广团队去哪里找
  • 专做机械类毕业设计的网站海淀区seo引擎优化
  • 网站图片倒计时怎么做的百度官方app下载
  • 莘县做网站推广全国各大新闻网站投稿
  • 武汉市勘察设计有限公司武汉seo招聘
  • 标识设计厂家南宁seo平台标准
  • 套别人代码做网站nba西部排名
  • 衡水企业网站制作广告传媒公司经营范围
  • 网站推广平台怎么做网站推广方式组合
  • 淘宝网的网站建设视频剪辑培训班一般学费多少
  • 珠海注册公司衡阳seo外包
  • 网站名称大全百度一下你就知道官页
  • 做网站上海公司可以下载新闻视频的网站
  • 有域名和虚拟服务器后怎么做网站1688黄页大全进口
  • 织梦下载网站模板抖音关键词挖掘工具
  • 网站运营是具体的如何在百度发布广告信息
  • 桂林视频网站制作免费推广网站平台
  • 江苏句容市疫情最新情况做关键词优化
  • 国外做节目包装的网站做网站推广的公司
  • 一起做网店一样的网站培训学校网站
  • 网站开发 实习报告软文范文大全
  • 崇安网站建设网络推广工作内容
  • 手机网站模板欣赏谷歌推广一年多少钱