GithubHelp home page GithubHelp logo

skeleton's Introduction

Skeleton

android 项目基本框架搭建 新版

gif图

    @Override
    public void initListener() {
        binding.tvLoad.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startRequestNetData(new IRequestNetData() {
                    @Override
                    public void loadNetData() {
                        loadNetData1();
                    }
                });
            }
        });
    }
    public void loadNetData1(){
            final Random rd = new Random();
            showLoading(true);//true代表加载中的视图背景是透明的
            requestData(apiService.getPageData(), new NetRequestWork.OnRequestListener<UgouCountBean>() {
                @Override
                public void onRecvDataBack(final UgouCountBean ugouCountBean) {
                    BaseApplication.mhandler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            int i = rd.nextInt(10);
                            if(i>0 && i<=3){////假设1~3网络数据请求成功
                                Toast.makeText(MainActivity.this,ugouCountBean.toString(),Toast.LENGTH_SHORT).show();
                                hideLoding();
                            }else if(i>3 && i<=6){//4~6服务器报异常
                                //throw new CustomDataException("模拟异常~~");
                                hideLoding();
                                showErrorView();
                            }else{//其它为服务器返回空数据
                                hideLoding();
                                showNoDataView();
                            }
                        }
                    },2000);
                }
                @Override
                public void onError(Throwable e) {
                    Toast.makeText(MainActivity.this,e.getMessage(),Toast.LENGTH_SHORT).show();
                    hideLoding();
                    showErrorView();
                }
            });
    }

####程序员只需要在适当的位置 该显示什么视图就显示什么视图 不需要考虑其它(如 加载失败/空视图/网络异常视图怎么重新加载数据 没有网络怎么显示没有网络的视图...) 程序员精力只要放在数据成功返回处理好数据怎么显示就可以了

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.