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

万网有网站建设吗做网站什么职业

万网有网站建设吗,做网站什么职业,wordpress数据库添加用户,网站的劣势使用Android Studio开发天气预报APP 今天我来分享一下如何使用Android Studio开发一个天气预报APP。在文中#xff0c;我们将使用第三方接口获取实时天气数据#xff0c;并显示在APP界面上。 步骤一#xff1a;创建新项目 首先#xff0c;打开Android Studio并创建一个新…使用Android Studio开发天气预报APP 今天我来分享一下如何使用Android Studio开发一个天气预报APP。在文中我们将使用第三方接口获取实时天气数据并显示在APP界面上。 步骤一创建新项目 首先打开Android Studio并创建一个新的项目。在创建新项目时我们需要设置项目名称、包名和支持的最低API级别。 步骤二 为了获取实时天气数据我们需要导入一个名为Retrofit的第三方库。可以使用以下代码在build.gradle文件中添加Retrofit库的依赖。 dependencies {implementation androidx.core:core-ktx:1.7.0implementation androidx.appcompat:appcompat:1.6.1implementation com.google.android.material:material:1.9.0implementation androidx.constraintlayout:constraintlayout:2.1.4testImplementation junit:junit:4.13.2androidTestImplementation androidx.test.ext:junit:1.1.5androidTestImplementation androidx.test.espresso:espresso-core:3.5.1 //networkimplementation com.squareup.retrofit2:retrofit:2.9.0implementation com.squareup.retrofit2:converter-gson:2.9.0 }步骤三获取API Key 为了使用OpenWeatherMap API您需要注册一个免费的API Key。请访问OpenWeatherMap官网进行注册并获取API Key。 步骤四创建接口 首先我们需要创建一个接口定义我们需要的网络请求方法。在这个例子中我们需要一个根据城市名称获取天气信息的方法 interface WeatherService {GET(weather)fun getWeatherByCityName(Query(q) cityName : String,Query(appid) apiKey : String) : CallWeatherResponse}步骤五构建对应的数据结构 这是对应的WeatherRespone数据结构用来序列化返回的json接口。 这个json结构可以从openweathermap的api里查看到 返回值在这里 根据OpenWeatherMap API的响应格式我们需要创建相应的数据模型。这里我们以WeatherResponse为例创建对应的数据模型类对应的kotlin结构体 data class WeatherResponse(SerializedName(coord)var coord: Coord? null,SerializedName(weather)var weather : ArrayListWeather,SerializedName(base)var base: String? null,SerializedName(main)var main: Main? null,SerializedName(visibility)var visibility: Int 0,SerializedName(wind)var wind: Wind ? null,SerializedName(clouds)var clouds: Clouds ? null,SerializedName(dt)val dt: Int,SerializedName(sys)var sys: Sys ? null,SerializedName(id)var id: Int 0,SerializedName(name)var name: String ? null,SerializedName(cod)var cod: Int )class Coord {SerializedName(lon)var lon : Float 0.toFloat()SerializedName(lat)var lat : Float 0.toFloat() }class Weather {SerializedName(id)var id: Int 0SerializedName(main)var main: String ? nullSerializedName(description)var description: String ? nullSerializedName(icon)var icon: String ? null }class Main {SerializedName(temp)var temp: Float 0.toFloat()SerializedName(pressure)var pressure: Int 0SerializedName(humidity)var humidity: Int 0SerializedName(temp_min)var temp_min: Float 0.toFloat()SerializedName(temp_max)var temp_max: Float 0.toFloat() }class Wind {SerializedName(speed)var speed: Float 0.toFloat()SerializedName(deg)var deg: Int 0 }class Clouds {SerializedName(clouds)var clouds: Int 0 }class Sys {SerializedName(type)var type: Int 0SerializedName(id)var id: Int 0SerializedName(message)var message: Float 0.toFloat()SerializedName(country)var country: String ? nullSerializedName(sunrise)var sunrise: Int 0SerializedName(sunset)var sunset: Int 0 }步骤六创建Retrofit实例 接下来我们需要创建一个Retrofit实例并配置相关参数。在这个例子中我们需要配置基础URL和Gson转换器 调用getWeatherByCityName(“London”)来获取伦敦的天气情况 object RetrofitClient {private const val BASE_URL https://api.openweathermap.org/data/2.5/private const val API_KEY add your api keyprivate val retrofit Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();private val weatherService: WeatherService by lazy { retrofit.create(WeatherService::class.java) }fun getWeatherByCityName(cityName: String) {val call weatherService.getWeatherByCityName(cityName, API_KEY)call.enqueue(object : CallbackWeatherResponse {override fun onResponse(call: CallWeatherResponse,response: ResponseWeatherResponse) {if (response.isSuccessful) {val weatherData response.body()handleWeatherData(weatherData)} else {handleWeatherFailure(response.message())}}override fun onFailure(call: CallWeatherResponse, t: Throwable) {handleWeatherFailure(t.message!!)}})}private fun handleWeatherData(weatherData: WeatherResponse?) {if (weatherData ! null) {println(coord: lat:${weatherData.coord?.lat},lon:${weatherData.coord?.lon})for(weather in weatherData.weather) {println(weather: id:${weather.id},main${weather.main}, description:${weather.description},icon:${weather.icon})}println(base:${weatherData.base})println(main: temperature:${weatherData.main?.temp},pressure:${weatherData.main?.pressure}, humidity:${weatherData.main?.humidity},temperature_min:${weatherData.main?.temp_min}, temperature_max:${weatherData.main?.temp_max})println(visibility:${weatherData.visibility})println(wind: speed:${weatherData.wind?.speed},deq:${weatherData.wind?.deg})println(clouds: clouds:${weatherData.clouds?.clouds})println(dt: ${weatherData.dt})println(sys: type:${weatherData.sys?.type},id:${weatherData.sys?.id},message:${weatherData.sys?.message} ,country:${weatherData.sys?.country},sunrise:${weatherData.sys?.sunrise},sunset:${weatherData.sys?.sunset})println(id: ${weatherData.id})println(name: ${weatherData.name})println(cod: ${weatherData.cod})}}private fun handleWeatherFailure(message: String) {println(Request failed: $message)} }步骤七程序的运行结果 W/ample.myweathe: Accessing hidden method Landroid/os/Trace;-asyncTraceBegin(JLjava/lang/String;I)V (light greylist, reflection) W/ample.myweathe: Accessing hidden method Landroid/os/Trace;-asyncTraceEnd(JLjava/lang/String;I)V (light greylist, reflection) W/ample.myweathe: Accessing hidden method Landroid/os/Trace;-traceCounter(JLjava/lang/String;I)V (light greylist, reflection) I/System.out: coord: lat:51.5085,lon:-0.1257 I/System.out: weather: id:804,mainClouds,description:overcast clouds,icon:04n I/System.out: base:stations I/System.out: main: temperature:285.53,pressure:1007,humidity:91,temperature_min:284.02,temperature_max:286.53 I/System.out: visibility:10000 I/System.out: wind: speed:0.82,deq:347 I/System.out: clouds: clouds:0 I/System.out: dt: 1690252945 I/System.out: sys: type:2,id:2075535,message:0.0,country:GB,sunrise:1690258398,sunset:1690315226 I/System.out: id: 2643743 I/System.out: name: London I/System.out: cod: 200 W/ample.myweathe: Accessing hidden method Landroid/graphics/FontFamily;-init()V (light greylist, reflection) W/ample.myweathe: Accessing hidden method Landroid/graphics/FontFamily;-addFontFromAssetManager(Landroid/content/res/AssetManager;Ljava/lang/String;IZIII[Landroid/graphics/fonts/FontVariationAxis;)Z (light greylist, reflection) W/ample.myweathe: Accessing hidden method Landroid/graphics/FontFamily;-addFontFromBuffer(Ljava/nio/ByteBuffer;I[Landroid/graphics/fonts/FontVariationAxis;II)Z (light greylist, reflection) W/ample.myweathe: Accessing hidden method Landroid/graphics/FontFamily;-freeze()Z (light greylist, reflection) W/ample.myweathe: Accessing hidden method Landroid/graphics/FontFamily;-abortCreation()V (light greylist, reflection) W/ample.myweathe: Accessing hidden method Landroid/graphics/Typeface;-createFromFamiliesWithDefault([Landroid/graphics/FontFamily;Ljava/lang/String;II)Landroid/graphics/Typeface; (light greylist, reflection)
http://www.sadfv.cn/news/54039/

相关文章:

  • 哈尔滨建站wordpress 添加导航
  • 在线营销网站建设长沙市网站推广电话
  • ipv6域名解析 做网站wordpress的模板是什么
  • 南昌哪里有网站建设基础网站建设
  • 网站建设与管理实践阿里巴巴logo含义
  • 凡科建站微信小程序垣曲网站建设
  • 手机版网站开发框架app模板
  • 如何招网站开发人员做加盟正规网站
  • 网站的开发工具建筑效果图素材网站
  • 简单的个人主页网站制作html设计之家下载
  • 互联网 网站设计江苏省宿迁市建设局网站
  • 网站制作视频课程做网站原型图是用什么软件
  • 阳泉网站建设哪家便宜杭州高端设计网站建设
  • 广州大型网站建设vi品牌设计
  • 专业网站建设服务公司哪家好网站关键词排名提高
  • 怎么查看网站用的php还是.net家庭宽带做网站
  • 重庆定制网站建设地址重庆妇科医院排名最好的医院
  • 互联网广告管理暂行办法百度网站排名搜行者seo
  • 网站制作的流程包括哪些有网站了小程序怎么做
  • 制作网站问题和解决方法wordpress手机端编辑
  • 网站建设视频大学学校网站建设方案
  • 新老网站做301跳转seo常用工具
  • 免费软文网站安徽专业做网站的公司
  • 邢台做网站哪家便宜wordpress 女性主题
  • 网站后台口令网站互动化
  • wordpress 弹出表单百度seo在线优化
  • google如何提交网站wordpress 插件哪里
  • dw做网站怎么加视频网站建设与运营 好考吗
  • 枣强网站建设培训学校seo产品是什么意思
  • 中国网站设计公司软件工程师报考条件