Koltin31,大牛深入讲解,高级安卓面试题

container: ViewGroup?,

savedInstanceState: Bundle?

): View? {

val orderView = View.inflate(activity, R.layout.fragment_order, null)

orderPresenter = OrderFragmentPresenter(this)

rvOrder = orderView.find(R.id.rv_order_list)

rvOrder.layoutManager = LinearLayoutManager(activity)

adapter = OrderRvAdapter(activity)

rvOrder.adapter = adapter

return orderView

}

override fun onActivityCreated(savedInstanceState: Bundle?) {

super.onActivityCreated(savedInstanceState)

//访问服务器,获取所有订单数据

val userId = TakeoutApp.sUser.id

if (-1 == userId) {

toast(“请先登录,再查看订单”)

} else {

orderPresenter.getOrderList(userId.toString())

}

}

fun onOrderSuccess(orderList: List) {

//TODO:给adapter设置数据

adapter.setOrderData(orderList)

toast(“服务器onOrderSuccess”)

}

fun onOrderFailed() {

toast(“服务器onOrderFailed”)

}

}

OrderFragmentPresenter.kt数据的请求和解析

package com.example.takeout.presenter

import com.example.takeout.model.beans.Order

import com.example.takeout.ui.fragment.OrderFragment

import com.google.gson.Gson

import com.google.gson.reflect.TypeToken

class OrderFragmentPresenter(val orderFragment: OrderFragment) : NetPresenter() {

fun getOrderList(userId: String) {

val takeoutorderCall = takeoutService.getOrderList()

takeoutorderCall.enqueue(callback)

}

override fun parserJson(json: String) {

//此处解析,List

val orderList: List =

Gson().fromJson(json, object : TypeToken<List>() {}.type)

if (orderList.isNotEmpty()) {

orderFragment.onOrderSuccess(orderList)

} else {

orderFragment.onOrderFailed()

}

}

}

OrderRvAdapter.kt订单界面RecycleView数据的填充

package com.example.takeout.ui.adapter

import android.content.Context

import android.content.Intent

import android.view.LayoutInflater

import android.view.View

import android.view.ViewGroup

import android.widget.TextView

import androidx.recyclerview.widget.RecyclerView

import com.example.takeout.R

import com.example.takeout.model.beans.Order

import com.mob.wrappers.PaySDKWrapper

import org.jetbrains.anko.find

class OrderRvAdapter (val context: Context) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

private var orderList: List = ArrayList()

fun setOrderData(orders: List) {

this.orderList = orders

notifyDataSetChanged()

}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {

// val itemView = View.inflate(context, R.layout.item_order_item, null)

//TODO:没有填充满,原因是recycleview的孩子,测量模式是UNSPECIFY

//通过返回值已经addview,如果attachToRoot使用true会再一次addView(),就会报错

val itemView = LayoutInflater.from(context).inflate(R.layout.item_order_item,parent, false)

return OrderItemHolder(itemView)

}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {

(holder as OrderItemHolder).bindData(orderList.get(position))

}

override fun getItemCount(): Int {

return orderList.size

}

inner class OrderItemHolder(item: View) : RecyclerView.ViewHolder(item) {

val tvSellerName: TextView

val tvOrderType: TextView

init {

//findviewbyId tv_order_item_seller_name tv_order_item_type

tvSellerName = item.find(R.id.tv_order_item_seller_name)

tvOrderType = item.find(R.id.tv_order_item_type) //订单状态

// item.setOnClickListener {

// val intent: Intent = Intent(context, OrderDetailActivity::class.java)

// intent.putExtra(“orderId”, order.id)

// intent.putExtra(“type”, order.type)

// context.startActivity(intent)

// }

}

fun bindData(order: Order) {

// tvSellerName.text = order.seller.name

tvOrderType.text = order.type

}

}

}

TakeoutService.kt使用Retrofit请求数据的封装

package com.example.takeout.model.net

import retrofit2.Call

import retrofit2.http.GET

interface TakeoutService {

//ex. @GET(“users/{user}/repos”)

//ex. fun listRepos(@Path(“user”) user: String): Call<List>

//http://127.0.0.1:8090/takeout?index=0

@GET(“takeout?index=0”)

fun getHomeInfo(): Call

//http://127.0.0.1:8090/takelogin?index=0

@GET(“takelogin?index=0”)

fun loginByPhone() : Call

//http://127.0.0.1:8090/takeorder?index=0

@GET(“takeorder?index=0”)

fun getOrderList() : Call

}

item_order_item.xml订单界面单个item数据的界面布局

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:background=“#fff”

android:orientation=“horizontal”>

<FrameLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”>

<ImageView

android:id=“@+id/iv_order_item_seller_logo”

android:layout_width=“50dp”

android:layout_height=“50dp”

android:layout_margin=“8dp”

android:src=“@mipmap/item_kfc” />

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_margin=“8dp”

android:orientation=“vertical”>

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:gravity=“center_vertical”>

<TextView

android:id=“@+id/tv_order_item_seller_name”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_marginLeft=“5dp”

android:layout_weight=“1”

android:singleLine=“true”

android:text=“肯德基宅急送(文化路店)”

android:textColor=“#000”

android:textSize=“20sp” />

<TextView

android:id=“@+id/tv_order_item_type”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“8dp”

android:textSize=“14sp”

android:text=“订单已完成”

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
img

写在最后

最后我想说:对于程序员来说,要学习的知识内容、技术有太多太多,要想不被环境淘汰就只有不断提升自己,从来都是我们去适应环境,而不是环境来适应我们!

这里附上上述的技术体系图相关的几十套腾讯、头条、阿里、美团等公司2021年的面试题,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。

相信它会给大家带来很多收获:

上述【高清技术脑图】以及【配套的架构技术PDF】可以点击下面链接免费获取

Android学习PDF+架构视频+面试文档+源码笔记

…(img-QqN8SD3h-1710666703162)]

写在最后

最后我想说:对于程序员来说,要学习的知识内容、技术有太多太多,要想不被环境淘汰就只有不断提升自己,从来都是我们去适应环境,而不是环境来适应我们!

这里附上上述的技术体系图相关的几十套腾讯、头条、阿里、美团等公司2021年的面试题,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。

相信它会给大家带来很多收获:

[外链图片转存中…(img-WVhXBABE-1710666703162)]

[外链图片转存中…(img-Suw7DAIc-1710666703163)]

上述【高清技术脑图】以及【配套的架构技术PDF】可以点击下面链接免费获取

Android学习PDF+架构视频+面试文档+源码笔记

当程序员容易,当一个优秀的程序员是需要不断学习的,从初级程序员到高级程序员,从初级架构师到资深架构师,或者走向管理,从技术经理到技术总监,每个阶段都需要掌握不同的能力。早早确定自己的职业方向,才能在工作和能力提升中甩开同龄人。

  • 13
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值