最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android完整的前后端交互參考案例

 更新時(shí)間:2021年09月10日 10:46:55   作者:Time .  
這篇文章主要介紹了Android完整的前后端交互參考案例,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

Android 前端獲取數(shù)據(jù)并顯示

API 連接獲取(~~Api.java)

文件創(chuàng)建

新建Kotlin class/file 中的 Interface 文件。

文件內(nèi)容

public interface CleaningDisinfectionApi {
    //綜合查詢清洗消毒列表
    @POST("formatdisinfection/getPage")
    Observable<CleaningDisinfectionData.CleaningDisinfectionInfoList> getCleaningDisinfection(@Header("Range") String page, @Body CleaningDisinfectionData.SearchCleaningDisinfectionRequest searchCleaningDisinfectionRequest);
}

POST

內(nèi)容格式固定,內(nèi)容根據(jù)結(jié)構(gòu)文檔請求不同數(shù)據(jù)組

@POST("formatdisinfection/getPage")

其格式固定,POST后內(nèi)容代表根據(jù)接口文檔進(jìn)行填寫。

在此接口中,請求數(shù)據(jù)組如圖所示==

Observable

Observable<CleaningDisinfectionData.CleaningDisinfectionInfoList> getCleaningDisinfection(@Header("Range") String page, @Body CleaningDisinfectionData.SearchCleaningDisinfectionRequest searchCleaningDisinfectionRequest);
CleaningDisinfectionData.CleaningDisinfectionInfoList

返回?cái)?shù)據(jù)列表,數(shù)據(jù)內(nèi)容根據(jù)需求自行設(shè)計(jì)

getCleaningDisinfection(@Header("Range") String page, @Body CleaningDisinfectionData.SearchCleaningDisinfectionRequest searchCleaningDisinfectionRequest)

頭部

函數(shù)格式確定,
Header為指定的內(nèi)容,
Body是數(shù)據(jù)請求文件(~~~~~~Data.~~~~~~Request)對象,在此請求數(shù)據(jù)中,一般請求整個(gè)完整的對象數(shù)據(jù)組。
設(shè)置數(shù)據(jù)是根據(jù)不同的需求顯示不同的數(shù)據(jù)。

數(shù)據(jù)請求以及設(shè)定(~~Data.java)

此部分主要完成利用Api接口,完成完整數(shù)據(jù)組的獲取,以及根據(jù)不同需求設(shè)定不同的返回?cái)?shù)據(jù)列表。

數(shù)據(jù)請求函數(shù)(public static class ~~~Request)

此函數(shù)請求完整的數(shù)據(jù)組。

即*根據(jù)接口文檔參數(shù)內(nèi)容,定義所有的成員變量,并于文檔參數(shù)一一對應(yīng)*,并定義其get和set方法。

private String date;//消毒日期
        private String amount;//餐具數(shù)量
        private  String coaCode;//企業(yè)許可證號
        private String coaName;//許可證企業(yè)名稱
        private String entCreditCode;//企業(yè)社會信用代碼
        private String enterpriseName;//企業(yè)名稱
        private String name;//餐具名稱
        private String way;//消毒方式
        private String person;//操作人姓名
        private String remark;//備注
        private String start;//開始日期
        private String end;//結(jié)束日期
        private String addTime;
        private String operator;
        private String operatorIp;
        private String operatorTime;


        private int id;
        private int start1;//開始時(shí)間 小時(shí)
        private int start2;//開始時(shí)間 分
        private int end1;//結(jié)束時(shí)間 小時(shí)
        private int end2;//結(jié)束時(shí)間  秒
        private int area;//企業(yè)所在區(qū)域
        private int caId;//從業(yè)人員ID

請求參數(shù)

數(shù)據(jù)返回列表函數(shù)( public static class ~~~List)

public static class CleaningDisinfectionInfoList{
        private String MESSAGE;
        private String STATUS;
        private List<Data> data;

        public String getMESSAGE() {
            return MESSAGE;
        }

        public void setMESSAGE(String MESSAGE) {
            this.MESSAGE = MESSAGE;
        }

        public String getSTATUS() {
            return STATUS;
        }

        public void setSTATUS(String STATUS) {
            this.STATUS = STATUS;
        }

        public List<Data> getData() {
            return data;
        }

        public void setData(List<Data> data) {
            this.data = data;
        }

        public static class Data implements Serializable{
            private String date;//消毒日期
            private String enterpriseName;//企業(yè)名稱
            private String amount;//餐具數(shù)量
            private String name;//餐具名稱
            private int area;//企業(yè)所在區(qū)域
            
            public String getDate() {
                return date;
            }

            public void setDate(String date) {
                this.date = date;
            }

            public String getEnterpriseName() {
                return enterpriseName;
            }

            public void setEnterpriseName(String enterpriseName) {
                this.enterpriseName = enterpriseName;
            }

            public String getAmount() {
                return amount;
            }

            public void setAmount(String amount) {
                this.amount = amount;
            }

            public String getName() {
                return name;
            }

            public void setName(String name) {
                this.name = name;
            }

            public int getArea() {
                return area;
            }

            public void setArea(int area) {
                this.area = area;
            }
        }
    }
}

成員變量

		private String MESSAGE;/
        private String STATUS;
        private List<Data> data;//變量類型為List,即將獲取的數(shù)據(jù)以List返回

返回?cái)?shù)據(jù)列表設(shè)置函數(shù)

public static class Data implements Serializable{
            private String date;//消毒日期
            private String enterpriseName;//企業(yè)名稱
            private String amount;//餐具數(shù)量
            private String name;//餐具名稱
            private int area;//企業(yè)所在區(qū)域
public String getDate() {
                return date;
            }

            public void setDate(String date) {
                this.date = date;
            }
            ············

定義返回?cái)?shù)據(jù)列表中的成員變量,并設(shè)定其getData和setData方法。

數(shù)據(jù)請求以及設(shè)定

數(shù)據(jù)請求

數(shù)據(jù)請求及設(shè)定在activity中完成。

private void getCleanDisinfetionData() {
        cleanningdisinfectionApi.getCleaningDisinfection(pageNo+":10", searchCleaningDisinfectionRequest)
                                .subscribeOn(Schedulers.io())
                                .observeOn(AndroidSchedulers.mainThread())
                                .subscribe(new Observer<CleaningDisinfectionData.CleaningDisinfectionInfoList>() {
                                    @Override
                                    public void onSubscribe(Disposable d) {
                                        Log.d(TAG, "onSubscribe:");
                                    }

                                    @Override
                                    public void onNext( CleaningDisinfectionData.CleaningDisinfectionInfoList list) {
                                        Log.d(TAG, "onNext:");
                                        if (list != null&&list.getSTATUS().equals("200") && list.getData() != null) {
                                            cleanDisinfectionList.addAll(list.getData());
                                            setListData();
                                        }
                                    }

                                    @Override
                                    public void onError(Throwable e) { Log.d(TAG, "onError:" + e.getMessage());}

                                    @Override
                                    public void onComplete() {
                                        Log.d(TAG, "onComplete:");
                                    }
                                });
    }
   

數(shù)據(jù)請求操作格式固定,即在activity中調(diào)用~~~Api進(jìn)行請求數(shù)據(jù),并將請求到的數(shù)據(jù)返回到List中。

數(shù)據(jù)顯示

private void setListData(){
        mainScroll.setAdapter(new CleaningDisinfectionAdapter(cleanDisinfectionList));
        if (RetrofitSingleton.dataNumber!=null){
            if (Integer.parseInt(RetrofitSingleton.dataNumber)<10000){
                resultNum.setText(RetrofitSingleton.dataNumber+"(家)");
            }
            else {
                resultNum.setText("10000+(家)");
            }
            if(cleanDisinfectionList.size()==Integer.parseInt(RetrofitSingleton.dataNumber)){
                Toast.makeText(FoodOperationSearchActivity.this,"已加載全部數(shù)據(jù)",Toast.LENGTH_SHORT).show();
                mRefreshLayout.setEnableLoadMore(false);
            }else {
                mRefreshLayout.setEnableLoadMore(true);
            }
        }
    }

數(shù)據(jù)顯示模塊,將請求到的數(shù)據(jù)傳遞到Adapter中,利用自己設(shè)置的Adapter完成數(shù)據(jù)顯示。

Adapter(適配器)設(shè)置

package com.upc.txgc.intelligentmarket2021.Views;

import android.graphics.drawable.GradientDrawable;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.upc.txgc.intelligentmarket2021.HttpRequests.HttpObjects.CleaningDisinfectionData;
import com.upc.txgc.intelligentmarket2021.HttpRequests.HttpObjects.LicenseData;
import com.upc.txgc.intelligentmarket2021.R;
import com.zzhoujay.richtext.spans.LongClickable;
import org.greenrobot.eventbus.EventBus;

import java.util.List;


public class CleaningDisinfectionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private static final String TAG = "CleaningDisinfection";
    private final List<CleaningDisinfectionData.CleaningDisinfectionInfoList.Data> mData;


    public static class ItemClickListener implements View.OnClickListener {

        private CleaningDisinfectionData.CleaningDisinfectionInfoList.Data cleandisinfectionList;
        private int position;

        public void onClick(View v) {
            if (cleandisinfectionList != null) {
                Log.d(TAG, "position:" + position);
                EventBus.getDefault().post(cleandisinfectionList);

                //設(shè)置點(diǎn)擊效果
                //statusChange(v);
            }
        }
    }

    public static class ScrollVH extends RecyclerView.ViewHolder {
        private View mView;
        private TextView enterpriseName;//企業(yè)名稱
        private TextView enterpriseArea;//企業(yè)所在區(qū)域
        private TextView disinfectionDate;//消毒日期
        private TextView name;//物品名稱
        private TextView amount;//物品數(shù)量
        GradientDrawable statusDrawable = new GradientDrawable();
        GradientDrawable licenseStatusDrawable = new GradientDrawable();


//創(chuàng)建自己的view
        public ScrollVH(View v) {
            super(v);
            mView = v;
            enterpriseName = v.findViewById(R.id.enterprise_name);
            enterpriseArea = v.findViewById(R.id.enterprise_area);
            disinfectionDate = v.findViewById(R.id.disinfection_date);
            name = v.findViewById(R.id.name);
            amount = v.findViewById(R.id.amount);
        }
    }
    //數(shù)據(jù)傳遞

    public CleaningDisinfectionAdapter(List<CleaningDisinfectionData.CleaningDisinfectionInfoList.Data>data){
        this.mData = data;
    }



    //綁定適配器界面
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.adapter_cleandisinfection, parent,
                        false);
        return new ScrollVH(view);
    }

    //設(shè)置數(shù)據(jù)
    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ScrollVH) {

            ScrollVH viewHolder = (ScrollVH) holder;
            if (mData.get(position).getEnterpriseName() != null) {
                viewHolder.enterpriseName.setText(mData.get(position).getEnterpriseName());
            }
            if (mData.get(position).getDate() != null){
                viewHolder.disinfectionDate.setText(mData.get(position).getDate());
            }
            //if (mData.get(position).getArea() != null){
               // viewHolder.enterpriseArea.setText(mData.get(position).getArea());
            //}
            if (mData.get(position).getAmount() != null){
                viewHolder.amount.setText(mData.get(position).getAmount());
            }
            if(mData.get(position).getName()!=null){
                viewHolder.name.setText(mData.get(position).getName());
            }

        }
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }
}

將數(shù)據(jù)通過構(gòu)造函數(shù)傳遞至適配器之中。

到此這篇關(guān)于Android完整的前后端交互參考案例的文章就介紹到這了,更多相關(guān)Android前后端交互內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Flutter啟動流程的深入解析

    Flutter啟動流程的深入解析

    這篇文章主要給大家介紹了關(guān)于Flutter啟動流程的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Flutter具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • Android開發(fā)之FloatingActionButton懸浮按鈕基本使用、字體、顏色用法示例

    Android開發(fā)之FloatingActionButton懸浮按鈕基本使用、字體、顏色用法示例

    這篇文章主要介紹了Android開發(fā)之FloatingActionButton懸浮按鈕基本使用、字體、顏色用法,結(jié)合實(shí)例形式分析了Android FloatingActionButton懸浮按鈕的基本功能、布局、使用方法及操作注意事項(xiàng),需要的朋友可以參考下
    2019-03-03
  • 詳談Android ListView的選擇模式

    詳談Android ListView的選擇模式

    下面小編就為大家?guī)硪黄斦凙ndroid ListView的選擇模式。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-04-04
  • 解決Android TabLayout 在寬屏幕上tab不能平均分配的問題

    解決Android TabLayout 在寬屏幕上tab不能平均分配的問題

    這篇文章主要介紹了解決Android TabLayout 在寬屏幕上tab不能平均分配的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • Android 簡單跳轉(zhuǎn)頁面工具的實(shí)例詳解

    Android 簡單跳轉(zhuǎn)頁面工具的實(shí)例詳解

    這篇文章主要介紹了Android 簡單跳轉(zhuǎn)頁面工具的實(shí)例詳解,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-03-03
  • Android圖片處理:識別圖像方向并顯示實(shí)例教程

    Android圖片處理:識別圖像方向并顯示實(shí)例教程

    在Android中使用ImageView顯示圖片的時(shí)候發(fā)現(xiàn)圖片顯示不正,方向偏了或者倒過來了,下面與大家分享下具體的解決方法,感性的朋友可以參考下
    2013-06-06
  • 在Android源碼中編譯出指定jar包的操作

    在Android源碼中編譯出指定jar包的操作

    這篇文章主要介紹了在Android源碼中編譯出指定jar包的操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • Android自定義LinearLayout布局顯示不完整的解決方法

    Android自定義LinearLayout布局顯示不完整的解決方法

    這篇文章主要給大家介紹了關(guān)于Android自定義LinearLayout但布局顯示不完整的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11
  • Android?OpenCV基礎(chǔ)API清晰度亮度識別檢測

    Android?OpenCV基礎(chǔ)API清晰度亮度識別檢測

    這篇文章主要為大家介紹了Android?OpenCV基礎(chǔ)API清晰度亮度識別檢測,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01
  • Android布局居中的幾種做法

    Android布局居中的幾種做法

    這篇文章主要介紹了Android布局居中的幾種做法的相關(guān)資料,需要的朋友可以參考下
    2016-09-09

最新評論

鄂托克前旗| 长治县| 大港区| 开江县| 金门县| 拜城县| 都安| 合水县| 成安县| 贡觉县| 深圳市| 循化| 城步| 景宁| 苍山县| 南充市| 石渠县| 什邡市| 惠水县| 辉县市| 新疆| 安平县| 静宁县| 泌阳县| 延寿县| 铜梁县| 庐江县| 罗平县| 沁源县| 麟游县| 沂南县| 岳阳县| 米脂县| 花垣县| 汶川县| 本溪| 镇安县| 泾阳县| 梨树县| 敦煌市| 盐边县|