Koltin31,2021年安卓开发者跳槽指南

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=“订单已完成”

android:textColor="#000"/>

<TextView

android:id="@+id/tv_order_item_time"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignParentLeft=“true”

android:text=“2016-09-04 18:00”

android:textSize=“12sp”/>

<View

android:layout_width=“match_parent”

android:layout_height=“2dp”

android:layout_marginTop=“5dp”

android:layout_marginBottom=“5dp”

android:background="@drawable/shape_background_division"/>

<RelativeLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_marginTop=“10dp”

android:layout_marginBottom=“10dp”

android:gravity=“center_vertical”>

<TextView

android:id="@+id/tv_order_item_foods"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignParentLeft=“true”

android:text=“红烧肉等3件商品”

android:textColor="#000"

android:textSize=“14sp”/>

<TextView

android:id="@+id/tv_order_item_money"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignParentRight=“true”

android:text=“¥31.00”

android:textColor="#000"

android:textS

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

ize=“12sp”/>

<View

android:layout_width=“match_parent”

android:layout_height=“2dp”

android:layout_marginTop=“5dp”

android:layout_marginBottom=“5dp”

android:background="@drawable/shape_background_division"/>

<RelativeLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_marginTop=“5dp”

android:layout_marginBottom=“5dp”

<TextView

android:id="@+id/tv_order_item_multi_function"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignParentRight=“true”

android:layout_marginRight=“10dp”

android:textSize=“16sp”

android:textColor="#3090E6"

android:background="@drawable/shape_background_stroke_blue"

android:padding=“4dp”

android:text=“再来一单”/>

Order.kt订单界面从服务器请求的数据

package com.example.takeout.model.beans

class Order {

var id: String? = null

var type: String? = null

var seller: Seller? = null

var rider: Rider? = null

var goodsInfos: List? = null

var distribution: Distribution? = null

var detail: OrderDetail? = null

inner class Rider {

var id = 0

var name: String? = null

var phone: String? = null // public Location location;

}

inner class OrderDetail {

var username: String? = null

var phone: String? = null

var address: String? = null

var pay: String? = null

var time: String? = null

}

上一篇:Hbase shell管理操作


下一篇:如何写好一个Java方法?